【发布时间】:2021-12-11 08:36:45
【问题描述】:
我有一个非常大的 .txt 格式的无向图数据集,我将其转换为 networkx 图。我需要提取一个包含 N 个节点的连接子图(如果可能,还有 E 个边,但不是必需的)。我该怎么做?这是我为查找最大连通子图而编写的代码:
def find_subgraph(graph):
connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))
largest_subgraph = max(connected_component_subgraphs, key=len)
return largest_subgraph
我想要的子图位于最小子图和最大子图的中间。任何帮助将不胜感激。
编辑:可以是任意N个节点,不需要特定节点
【问题讨论】:
标签: python-3.x graph networkx connected-components subgraph