H = list(nx.connected_component_subgraphs(G))[0]
博主本来想用以上代码获得大图的最大连通子图的,但出现了module 'networkx' has no attribute 'connected_component_subgraphs'
问题。
这是因为 nx.connected_component_subgraphs 在networkx 2.4版本已经完全废除了,我们可以采取下面代码获得 最大连通子图:
H = list(G.subgraph(c) for c in nx.connected_components(G))[0]
另:既然是因为2.4版本废弃了这个方法,那如果重装为2.4以前的版本应该也可以直接用nx.connected_component_subgraphs()
函数。