简体   繁体   English

'Graph'对象在networkx模块python中没有属性'nodes_iter'

[英]'Graph' object has no attribute 'nodes_iter' in networkx module python

I have the below function in python2.7 using networkx module which produces the error. 我使用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)

Error: 错误:

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'

Does anybody have any idea what has been wrong? 有谁知道出了什么问题?

You are probably using the pre-release version of networkx-2.0 which has removed the nodes_iter() method and now provides the the nodes() method with the same functionality. 您可能正在使用已删除nodes_iter()方法的networkx-2.0的预发布版本,现在提供具有相同功能的nodes()方法。 See this for details on the networkx-2.0 changes. 请参阅有关networkx-2.0更改的详细信息。

Just in case the link changes again, I'm going to post the actual solution here for future reference. 为了防止链接再次发生变化,我将在此发布实际解决方案以供将来参考。

From NetworkX 2.0 forward, you should change the following line of code from: 从NetworkX 2.0开始,您应该更改以下代码行:

for n, d in H.nodes_iter(data=True):

to: 至:

for n, d in list(H.nodes(data=True)):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 矩阵对象没有属性节点networkX python - Matrix object has no attribute nodes networkX python AttributeError: 模块“networkx”没有属性“Graph” - AttributeError: module 'networkx' has no attribute 'Graph' 模块“ networkx”没有属性“ add_nodes_from” - module 'networkx' has no attribute 'add_nodes_from' AttributeError:模块“ networkx”没有属性“ complete_graph” - AttributeError: module 'networkx' has no attribute 'complete_graph' neighbors = G.neighbors_iter AttributeError:“图形”对象没有属性“ neighbors_iter” - neighbors=G.neighbors_iter AttributeError: 'Graph' object has no attribute 'neighbors_iter' AttributeError: &#39;set&#39; 对象没有与 NetworkX 一起使用的属性 &#39;number_of_nodes&#39; - AttributeError: 'set' object has no attribute 'number_of_nodes' working with NetworkX 在 NetworkX 中打开 json 图会产生“模块‘networkx’没有属性‘json_graph’” - Open json graph in NetworkX yields “module 'networkx' has no attribute 'json_graph' ” 在python中访问networkx图的节点 - Accessing nodes of networkx graph in python Python Boto3 &#39;StreamingBody&#39; 对象没有属性 &#39;iter_lines&#39; - Python Boto3 'StreamingBody' object has no attribute 'iter_lines' python-igraph&#39;模块&#39;对象中的错误没有属性&#39;Graph&#39; - Error in python-igraph 'module' object has no attribute 'Graph'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM