簡體   English   中英

AttributeError:模塊“networkx”沒有屬性“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM