【发布时间】:2018-04-20 01:05:14
【问题描述】:
我的 networkx 代码有点问题。 我试图从图中的一个节点中找到所有邻居,但是....
neighbor = Graph.neighbors(element)
print(neighbor)
输出:
<dict_keyiterator object at 0x00764BA0>
而不是我应该得到的所有邻居......我的一个朋友,他使用的是旧版本的 networkx 没有得到这个错误,他的代码完全相同并且运行良好。
谁能帮我?降级我的networkx不是一种选择。
编辑:
这是我的完整代码
Graph = nx.read_graphml('macbethcorrected.graphml')
actors = nx.nodes(Graph)
for actor in actors:
degree = Graph.degree(actor)
neighbor = Graph.neighbors(actor)
print("{}, {}, {}".format(actor, neighbor, degree))
这是我正在使用的图表: http://politicalmashup.nl/new/uploads/2013/09/macbethcorrected.graphml
【问题讨论】:
-
您能提供minimal, complete, and verifiable example吗?还有你用的是什么networkx版本?
-
为你编辑了我的帖子,你能用这个吗?
-
谢谢。似乎在networkx 1.11(Python 3.5)上为我工作。你用的是哪个版本?
-
我使用的是networkx 2.0...
-
我建议阅读networkx.github.io/documentation/latest/release/… --- 这是将代码从networkx 1.x 修改为2.0 的指南
标签: python-3.x graph nodes networkx