I'm trying to get edges that have a certain attribute from a graph without using get_edge_attributes() function. I need a more flexible way of doing it. I can get node attributes but since I'm new at python edges seem difficult
G = nx.read_graphml("test.graphml")
for n in G:
print "%s\t%s" %(n, G.node[n].get(attr))
for (s,d) in G: # and here is my problem
print "%s->%s\t%s" %(s, d, G.edge[s][d].get(attr))
You can use the G.edges() or G.edges_iter() methods to loop over all of the graph edges.
In [1]: import networkx as nx
In [2]: G = nx.Graph()
In [3]: G.add_edge(1,2,weight=7)
In [4]: G.add_edge(2,3,weight=10)
In [5]: for u,v,a in G.edges(data=True):
print u,v,a
...:
1 2 {'weight': 7}
2 3 {'weight': 10}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With