Attribute of a MultiDiGraph Edge

2019-07-22 04:04发布

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

1条回答
劳资没心,怎么记你
2楼-- · 2019-07-22 04:27

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
查看更多
登录 后发表回答