我正在尝试运行这段代码:
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)
根据 this answer .
关于python - 最大错误(nx.connected_component_subgraphs(),)没有属性 'connected_component_subgraphs',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64198940/