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)。在數(shù)據(jù)集中有兩個庫(電影和演員),它的形式是二分圖。我想獲得電影節(jié)點的連接組件。---------------------------------------------------------------------------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貢獻1856條經(jīng)驗 獲得超11個贊
connected_component_subgraphs 已從 networkx 庫中刪除。您可以使用棄用通知中描述的替代方法。
對于您的示例,請參閱以下代碼:
A = (B.subgraph(c) for c in nx.connected_components(B)) A = list(A)[0]
月關(guān)寶盒
TA貢獻1772條經(jīng)驗 獲得超5個贊
使用以下代碼進行單行替代
A=list(B.subgraph(c) for c in nx.connected_components(B))[0]
或者你可以安裝以前版本的networkx
pip install networkx==2.3
Helenr
TA貢獻1780條經(jīng)驗 獲得超4個贊
首先我得到
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]
添加回答
舉報
0/150
提交
取消
