NetworkX - 在图表上查找点的自然簇

eri*_*mjl 4 graph networkx python-2.7

这里仍然是NetworkX的新手,但我希望能够查询NetworkX图以查找节点集群中的所有节点.这是我生成的示例图: 节点网络

如您所见,有节点集群.在每个集群中,每个节点都连接到每个其他节点.您可以在下面放大五个这样的聚类中看到: 放大5个集群

我希望能够找到如何提取每个节点的节点.每个节点都用一个长名称命名(例如,"A/Vietnam/2009/8/431"),我知道如何使用NetworkX的功能剔除单个节点,但我不知道如何连接所有节点该群集中的节点.首选语言是Python(2.7),我一直在使用NetworkX包.

谢谢大家!

Vik*_*ram 9

     import networkx as nx

     #G is the networkx graph 
     sub_graphs = nx.connected_component_subgraphs(G)

     #n gives the number of sub graphs
     n = len(sub_graphs)

     # you can now loop through all nodes in each sub graph
     for i in range(n):
         print "Subgraph:", i, "consists of ",sub_graphs[i].nodes()
Run Code Online (Sandbox Code Playgroud)

  • 从 2.5 版开始,正确的函数名称是“nx.connected_components()”。 (3认同)