![](/img/trans.png)
[英]inheriting networkx Graph and using nx.connected_component_subgraphs
[英]Error for max(nx.connected_component_subgraphs(),) no attribute 'connected_component_subgraphs'
我正在嘗試運行此代碼:
graph = nx.Graph()
largest_subgraph = max(nx.connected_component_subgraphs(graph), key=len)
但我收到此錯誤消息:
AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'
我該如何解決?
connected_component_subgraphs() 已從 2.4 版中刪除。
相反,使用這個:
graph = nx.Graph()
connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))
largest_subgraph = max(connected_component_subgraphs, key=len)
根據這個答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.