![](/img/trans.png)
[英]Error for max(nx.connected_component_subgraphs(),) no attribute '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]
尝试使用 nx.connected_component_subgraphs(G) 时出现以下错误。 请帮助解决这个问题。
在数据集中有两个库(电影和演员),它的形式是二分图。
我想获得电影节点的连接组件。
----> 1 A = list(nx.connected_component_subgraphs(B))[0] 中的 AttributeError Traceback(最近一次调用最后一次)
AttributeError:模块“networkx”没有属性“connected_component_subgraphs”
这在 2.1 版中已被弃用,最终在 2.4 版中被删除。
请参阅这些说明
使用
(G.subgraph(c) for c in connected_components(G))
或
(G.subgraph(c).copy() for c in connected_components(G))
connected_component_subgraphs
已从 networkx 库中删除。 您可以使用弃用通知中描述的替代方法。
对于您的示例,请参阅以下代码:
A = (B.subgraph(c) for c in nx.connected_components(B))
A = list(A)[0]
使用以下代码进行单行替代
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
或者你可以安装以前版本的networkx
pip install networkx==2.3
首先我得到
AttributeError:模块“matplotlib.cbook”没有属性“iterable”。
为了解决上述错误,我升级了 networkx 使用
pip install --upgrade --force-reinstall network
它安装了 unetworkx-2.6.3,我得到了错误
AttributeError:模块 networkx 没有属性 connected_component_subgraphs。
我使用了 ABHISHEK D 提到的以下代码,它解决了。 谢谢。
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.