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]當(dāng)我嘗試使用時(shí),我得到下面給出的錯(cuò)誤。nx.connected_component_subgraphs(G)在數(shù)據(jù)集中有兩個(gè)庫姆(電影和演員),它以二分圖的形式出現(xiàn)。我想獲取電影節(jié)點(diǎn)的連接組件。---------------------------------------------------------------------------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貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊
connected_component_subgraphs
已從網(wǎng)絡(luò)庫中刪除。您可以使用棄用通知中描述的替代方法。
有關(guān)您的示例,請(qǐng)參閱以下代碼:
A = (B.subgraph(c) for c in nx.connected_components(B)) A = list(A)[0]

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
將以下代碼用于單行替代代碼
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
或者,您可以安裝以前版本的網(wǎng)絡(luò)x
pip install networkx==2.3

蝴蝶刀刀
TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊
首先我得到了
屬性錯(cuò)誤:模塊“matplotlib.cbook”沒有屬性“可迭代”。
為了修復(fù)上述錯(cuò)誤,我使用升級(jí)了網(wǎng)絡(luò)x
pip install --upgrade --force-reinstall network
它安裝了未工作x-2.6.3,我得到錯(cuò)誤
屬性錯(cuò)誤:模塊網(wǎng)絡(luò)x沒有屬性connected_component_subgraphs。
我使用了ABHISHEK D提到的以下代碼,它解決了。謝謝。
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
添加回答
舉報(bào)
0/150
提交
取消