我使用in_edges
doc中所述的方法将所有传入边缘都传递到G[myIndex]
DiGraph中的节点,但实际上for u, v, data in G.in_edges(G[maxIndex], data=True):
给了我所有out_edges。不是我想要的输出。
当我尝试时,G.out_edges
它给我所有来自所有out_edges的边缘(例如离所需输出更远的一步)。将所需的节点传递给nbunch
参数时,我缺少什么吗?对我来说,这似乎是个错误,但是在那种情况下,用谷歌搜索起来很容易,所以我认为我错了。
我认为您误会了G[maxIndex]
。它实际上将为您提供节点的边缘,maxIndex
然后从那堆节点中获得边缘。
如果您只想要给定节点的边缘,则可以这样做G.in_edges(maxIndex, data=True)
。像这样:
G = nx.DiGraph()
G.add_weighted_edges_from([(2, 1, 3.0), (3,1, 5.0), (4, 1, -1.0), (4, 2, 8.0)])
maxIndex = 1 # Here
for u, v, data in G.in_edges(maxIndex, data=True):
print u,v,data
输出:
2 1 {'weight': 3.0}
3 1 {'weight': 5.0}
4 1 {'weight': -1.0}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句