[英]'Graph' object has no attribute 'nodes_iter' in networkx module python
我使用networkx模块在python2.7中有以下函数,产生错误。
for H in networkx.connected_component_subgraphs(G):
bestScore = -1.0
for n, d in H.nodes_iter(data=True):
if d['Score'] > bestScore:
bestScore = d['Score']
bestSV = n
if bestSV is not None:
selectedSVs.add(bestSV)
错误:
Traceback (most recent call last):
File "cnvClassifier.py", line 128, in <module>
for n, d in H.nodes_iter(data=True):
AttributeError: 'Graph' object has no attribute 'nodes_iter'
有谁知道出了什么问题?
您可能正在使用已删除nodes_iter()方法的networkx-2.0的预发布版本,现在提供具有相同功能的nodes()方法。 请参阅此有关networkx-2.0更改的详细信息。
为了防止链接再次发生变化,我将在此发布实际解决方案以供将来参考。
从NetworkX 2.0开始,您应该更改以下代码行:
for n, d in H.nodes_iter(data=True):
至:
for n, d in list(H.nodes(data=True)):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.