在使用时nx.connected_component_subgraphs(G)[0],遇到报错: TypeError: 'generator' object has no attribute '__getitem__' 解决方法: 从1.9版本开始,connected_components的输出不再是list形式,而是generator 如果仍需使用list输出,可以采用 list(connected_components(G)) 输出 另外, 获取最大连通子图时如果可以...
在无向图中,我想要找到最大连通分量。我阅读了networkX的API文档,找到了这个函数nx.connected_component_subgraphs()。但是我不知道如何使用它,因为它的返回值是一个生成器,我不能导出最大连通组件的子图。 它和一个一样。但是图是有向的。我想找出有向图的最大弱连通分量。问题 ...
使用networkx的connected_components函数获取所有连接的组件: 代码语言:txt 复制 components = list(nx.connected_components(G)) 创建集团对象并将连接的组件添加到集团中: 代码语言:txt 复制 集团= [] for component in components: 集团.append(list(component)) 完成以上步骤后,你将得到一个包含所有连接的组件的集...
# 找出最大连通数的子图 Gcc = sorted(nx.connected_component_subgraphs(G), key=len, reverse=True) G0 = Gcc[0] nx.draw_networkx_edges(G0, pos, with_labels=False, edge_color='r', width=6.0) # 画出其他连通数子图 [nx.draw_networkx_edges(Gi, pos, with_labels=False, edge_color='r',...
Gc = max(nx.connected_component_subgraphs(G), key=len)为了以后查此问题的人方便!
sub_graphs=nx.connected_component_subgraphs(G) for i,sub_graph in enumerate(sub_graphs): n_nodes=len(sub_graph.nodes()) if n_nodes >= M: print("Subgraph {0} has {1} nodes {2}".format(i,n_nodes,sub_graph.nodes())) nx.draw(G) ...
Have you noticed that 'connected_component_subgraphs' is removed in 'networkx' version 2.4?Contributor Jessime commented May 30, 2020 I have; networkx is specifically pinned to avoid this problem until I get a chance to fix it. https://github.com/CalabreseLab/seekr/blob/master/setup.py#...
44 Gcc = sorted(nx.connected_component_subgraphs(G), key=len, reverse=True)45 G0 = Gcc[0]46 nx.draw_networkx_edges(G0, pos,47 with_labels=False,48 edge_color='r',49 width=6.050 )51 # show other connected components52 for Gi in Gcc[1:]:53 if len(Gi) > 1:54 nx.draw_...
由于整个网络过于庞大,我们会将整个网络模型G拆为多个子网络放到subgraphs中。 subgraphs = [gforginnx.connected_component_subgraphs(G.to_undirected())] subgraphs= sorted(subgraphs, key=lambdax: x.number_of_nodes(), reverse=True)print([s.number_of_nodes()forsinsubgraphs[:10]]) ...
sub_graphs=nx.connected_component_subgraphs(G)fori,sub_graphinenumerate(sub_graphs): n_nodes=len(sub_graph.nodes())ifn_nodes >=M:print("Subgraph {0} has {1} nodes {2}".format(i,n_nodes,sub_graph.nodes())) nx.draw(G) plt.show() ...