![](/img/trans.png)
[英]How can i get the the two nodes (coordinates) between a edge? In OSMNX if i had (u,v,x) by ox.distance.nearest_edges
[英]How to get the data for the edge between two nodes?
我想获得 networkx 图中两个节点之间的边。 更具体地说,我想获得一些与这条边相关的数据。 我先验地知道这两个节点是链接的。 有没有一个功能可以做到这一点?
边缘数据存储在字典中。 要访问该字典,请使用get_edge_data()
。
import networkx as nx
G=nx.Graph()
G.add_edge(1,2, weight=5)
G.get_edge_data(1,2)
> {'weight': 5}
如果你想遍历所有的边,你可以使用G.edges(data=True)
H = nx.Graph()
H.add_edge(2, 3, color = 'red')
H.add_edge(1, 2, weight = 4)
for u,v,data in H.edges(data=True):
print(u, v, data)
> 1 2 {'weight': 4}
> 2 3 {'color': 'red'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.