python - AttributeError:模块“networkx”没有属性“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)
。
在数据集中有两个库(电影和演员),它的形式是二分图。
我想获得电影节点的连接组件。
---------------------------------------------------------------------------
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'
解决方案
这在 2.1 版中已被弃用,最终在 2.4 版中被删除。
请参阅这些说明
利用
(G.subgraph(c) for c in connected_components(G))
或者
(G.subgraph(c).copy() for c in connected_components(G))
推荐阅读
- vba - 在 Mac 上的 powerpoint 幻灯片中添加可点击的复选框
- python - 如何使用beautifulsoup 抓取网站上的数据以查看更多信息
- git - Anaconda/Git:git branch 命令是静默的,尽管它在 WSL Ubuntu 中工作
- google-sheets-formula - 用于匹配公司 URL 的 GoogleSheet 公式
- php - Codeception project can't find AcceptanceTester
- github - 如何获取 Github 管理员操作的 Slack 通知?
- php - Phalcon 停止视图在 dispatch() 后回显
- laravel - Laravel:如何将 pdf 文件直接上传到 Google Cloud Storage 存储桶而无需先保存在本地
- node.js - 使用 Sendgrid/mail 和 nodejs 防止未处理的承诺拒绝
- ruby-on-rails - 迁移变化