本文介绍了MultiDiGraph边的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请在networkx中使用multiDiGraph,其边缘由列表边缘中的元组表示,如何访问或打印出属性字典中的属性元素,例如如何打印multiDiGraph的长度或类型或泳道等
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})]
下面的print语句适用于Digraph,但MultiDiGraph却给出了错误
The print statement below works for a Digraph but gives an error for the MultiDiGraph
print i, X[i[0]][i[1]]['length']
谢谢
推荐答案
如果我了解您想要的内容,则可以使用get_edge_data
:
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
这篇关于MultiDiGraph边的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!