猿问

AttributeError:模块“networkx”没有属性

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)。


在数据集中有两个库(电影和演员),它的形式是二分图。


我想获得电影节点的连接组件。


---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-16-efff4e6fafc4> in <module>

----> 1 A = list(nx.connected_component_subgraphs(B))[0]


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


HUWWW
浏览 564回答 4
4回答

慕神8447489

这在 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&nbsp;已从 networkx 库中删除。您可以使用弃用通知中描述的替代方法。对于您的示例,请参阅以下代码:A&nbsp;=&nbsp;(B.subgraph(c)&nbsp;for&nbsp;c&nbsp;in&nbsp;nx.connected_components(B)) A&nbsp;=&nbsp;list(A)[0]

月关宝盒

使用以下代码进行单行替代A=list(B.subgraph(c)&nbsp;for&nbsp;c&nbsp;in&nbsp;nx.connected_components(B))[0]或者你可以安装以前版本的networkxpip&nbsp;install&nbsp;networkx==2.3

Helenr

首先我得到AttributeError:模块“matplotlib.cbook”没有属性“iterable”。为了解决上述错误,我升级了 networkx 使用pip&nbsp;install&nbsp;--upgrade&nbsp;--force-reinstall&nbsp;&nbsp;network它安装了 unetworkx-2.6.3,我得到了错误AttributeError:模块 networkx 没有属性 connected_component_subgraphs。我使用了 ABHISHEK D 提到的以下代码,它解决了。谢谢。A=list(B.subgraph(c)&nbsp;for&nbsp;c&nbsp;in&nbsp;nx.connected_components(B))[0]
随时随地看视频慕课网APP

相关分类

Python
我要回答