AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'

时光毁灭记忆、已成空白 提交于 2020-12-06 04:37:01

问题


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). 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]

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'


回答1:


This was deprecated with version 2.1, and finally removed with version 2.4.

See these instructions

Use (G.subgraph(c) for c in connected_components(G))

Or (G.subgraph(c).copy() for c in connected_components(G))




回答2:


connected_component_subgraphs has been removed from the networkx library. 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]


来源:https://stackoverflow.com/questions/61154740/attributeerror-module-networkx-has-no-attribute-connected-component-subgraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!