gpt4 book ai didi

python - MultiDiGraph 边的属性

转载 作者:行者123 更新时间:2023-11-28 22:50:25 25 4
gpt4 key购买 nike

对于 networkx 中的 multiDiGraph,其边由列表边中的元组表示,请问我如何访问或打印出属性字典中的属性元素,例如我怎样才能打印出 multiDiGraph 的长度或类型或 channel 等

i = [(1001, 7005,{'length':0.35, 'modes':'cw', 'type':'99', 'lanes':9})]

下面的打印语句适用于有向图,但对于多有向图会出错

print i, X[i[0]][i[1]]['length']

谢谢

最佳答案

如果我明白你想要什么,那么你可以使用 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

关于python - MultiDiGraph 边的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22655805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com