简体   繁体   English

AttributeError:模块“networkx”没有属性“connected_component_subgraphs”

[英]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.

相关问题 max(nx.connected_component_subgraphs(),) 的错误没有属性“connected_component_subgraphs” - Error for max(nx.connected_component_subgraphs(),) no attribute 'connected_component_subgraphs' AttributeError: 模块“networkx”没有属性“Graph” - AttributeError: module 'networkx' has no attribute 'Graph' AttributeError:模块“networkx”没有属性“utils” - AttributeError: module 'networkx' has no attribute 'utils' 继承networkx图并使用nx.connected_component_subgraphs - inheriting networkx Graph and using nx.connected_component_subgraphs 从 NetworkX 图中查找连接组件内的子图 - Find Subgraphs inside a Connected Component from a NetworkX Graph AttributeError:'module'对象没有networkx 1.11属性'graphviz_layout' - AttributeError: 'module' object has no attribute 'graphviz_layout' with networkx 1.11 AttributeError:模块“ networkx”没有属性“ complete_graph” - AttributeError: module 'networkx' has no attribute 'complete_graph' AttributeError:'module'对象没有networkx库的属性'write_dot' - AttributeError: 'module' object has no attribute 'write_dot' for networkx library AttributeError:模块“matplotlib.cbook”在 Networkx 中没有属性“is_numlike” - AttributeError: module 'matplotlib.cbook' has no attribute 'is_numlike' in Networkx 如何在NetworkX中仅绘制前50-100个连接的组件子图; 一次绘制多个子图 - How to graph only top 50-100 connected component subgraphs in NetworkX; drawing multiple subgraphs at once
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM