为了账号安全,请及时绑定邮箱和手机立即绑定

属性错误:模块“网络x”没有属性“connected_component_subgraphs”

属性错误:模块“网络x”没有属性“connected_component_subgraphs”

Qyouu 2022-10-05 09:38:05
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'
查看完整描述

4 回答

?
猛跑小猪

TA贡献1858条经验 获得超8个赞

这在版本 2.1 中已弃用,最终在版本 2.4 中删除。

请参阅这些说明

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

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


查看完整回答
反对 回复 2022-10-05
?
收到一只叮咚

TA贡献1821条经验 获得超4个赞

connected_component_subgraphs已从网络库中删除。您可以使用弃用通知中描述的替代方法。

有关您的示例,请参阅以下代码:

A = (B.subgraph(c) for c in nx.connected_components(B))
A = list(A)[0]


查看完整回答
反对 回复 2022-10-05
?
繁花如伊

TA贡献2012条经验 获得超12个赞

将以下代码用于单行替代代码

A=list(B.subgraph(c) for c in nx.connected_components(B))[0]

或者,您可以安装以前版本的网络x

pip install networkx==2.3


查看完整回答
反对 回复 2022-10-05
?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

首先我得到了

属性错误:模块“matplotlib.cbook”没有属性“可迭代”。

为了修复上述错误,我使用升级了网络x

pip install --upgrade --force-reinstall  network

它安装了未工作x-2.6.3,我得到错误

属性错误:模块网络x没有属性connected_component_subgraphs。

我使用了ABHISHEK D提到的以下代码,它解决了。谢谢。

A=list(B.subgraph(c) for c in nx.connected_components(B))[0]


查看完整回答
反对 回复 2022-10-05
  • 4 回答
  • 0 关注
  • 79 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信