[英]AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'
B = nx.Graph()
B.add_nodes_from(data['movie'].unique(), bipartite=0, label='movie')
B.add_nodes_from(data['actor'].unique(), bipartite=1, label='actor')
B.add_edges_from(edges, label='acted')
A = list(nx.connected_component_subgraphs(B))[0]
I am getting the below given error when am trying to use nx.connected_component_subgraphs(G).尝试使用 nx.connected_component_subgraphs(G) 时出现以下错误。 Please help with this issue.
请帮助解决这个问题。
In the dataset there are two coumns(movie and actor), and it's in the form bipartite graph.在数据集中有两个库(电影和演员),它的形式是二分图。
I want to get connected components for the movie nodes.我想获得电影节点的连接组件。
AttributeError Traceback (most recent call last) in ----> 1 A = list(nx.connected_component_subgraphs(B))[0] ----> 1 A = list(nx.connected_component_subgraphs(B))[0] 中的 AttributeError Traceback(最近一次调用最后一次)
AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' AttributeError:模块“networkx”没有属性“connected_component_subgraphs”
This was deprecated with version 2.1, and finally removed with version 2.4.这在 2.1 版中已被弃用,最终在 2.4 版中被删除。
See these instructions请参阅这些说明
Use
(G.subgraph(c) for c in connected_components(G))
使用
(G.subgraph(c) for c in connected_components(G))
Or
(G.subgraph(c).copy() for c in connected_components(G))
或
(G.subgraph(c).copy() for c in connected_components(G))
connected_component_subgraphs
has been removed from the networkx library. connected_component_subgraphs
已从 networkx 库中删除。 You can use the alternative described in the deprecation notice.您可以使用弃用通知中描述的替代方法。
For your example, refer to the code below:对于您的示例,请参阅以下代码:
A = (B.subgraph(c) for c in nx.connected_components(B))
A = list(A)[0]
Use the following code for single line alternative使用以下代码进行单行替代
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
Or you can install the previous version of networkx或者你可以安装以前版本的networkx
pip install networkx==2.3
First I got首先我得到
AttributeError: module 'matplotlib.cbook' has no attribute 'iterable'.
AttributeError:模块“matplotlib.cbook”没有属性“iterable”。
To fix the above error, I upgraded networkx using为了解决上述错误,我升级了 networkx 使用
pip install --upgrade --force-reinstall network
It installed unetworkx-2.6.3, I got the error它安装了 unetworkx-2.6.3,我得到了错误
AttributeError: module networkx has no attribute connected_component_subgraphs.
AttributeError:模块 networkx 没有属性 connected_component_subgraphs。
I used the below code as mentioned by ABHISHEK D, it resolved.我使用了 ABHISHEK D 提到的以下代码,它解决了。 Thanks.
谢谢。
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.