Reputation: 1109
Please for a multiDiGraph in networkx with edge represented by the tuple in the list edge, how can I access or print out the attribute elements in the dictionary of attributes e.g. how can i print out length or type or lanes etc for a multiDiGraph
i = [(1001, 7005,{'length':0.35, 'modes':'cw', 'type':'99', 'lanes':9})]
The print statement below works for a Digraph but gives an error for the MultiDiGraph
print i, X[i[0]][i[1]]['length']
Thank you
Upvotes: 2
Views: 738
Reputation: 393963
If I understand what you want then you can use get_edge_data
:
In [35]:
import networkx as nx
G = nx.MultiDiGraph()
G.add_edge(1001, 7005, length=0.35, modes='cw', type='99', lanes=9)
G.edges(data=True)
Out[35]:
[(1001, 7005, {'lanes': 9, 'length': 0.35, 'modes': 'cw', 'type': '99'})]
In [34]:
G.get_edge_data(1001, 7005)[0]['length']
Out[34]:
0.35
Upvotes: 4