NetworkX-在图上查找点的自然簇 [英] NetworkX - Finding the natural clusters of points on a graph
问题描述
这里仍然是NetworkX的新功能,但是我希望能够查询NetworkX图以找到节点集群中的所有节点.这是我生成的示例图:
Still kinda new to NetworkX here, but I wanted to be able to query a NetworkX graph to find all nodes within a cluster of nodes. Here is an example graph I had generated:
如您所见,存在节点簇.在每个群集中,每个节点都连接到每个其他节点.您可以在下面的五个此类集群的放大图中看到:
As you can see, there are clusters of nodes. Within each cluster, every node is connected to every other node. You can see that in a zoom-up of five such clusters below:
我希望能够找到如何提取出每个单独的节点簇的方法.每个节点都以一个长名称命名(例如,"A/Vietnam/2009/8/431"),我知道如何使用NetworkX的功能探出单个节点,但是我不知道如何使所有节点连接该群集中的节点.首选语言是Python(2.7),并且我一直在使用NetworkX软件包.
I'd like to be able to find out how I can extract out each individual cluster of nodes. Each node is named with a long name ("A/Vietnam/2009/8/431", for example), and I know how to fish out an individual node using NetworkX's functions, but I don't know how to get all connected nodes within that cluster. Language of preference is Python (2.7), and I have been using the NetworkX package in conjunction.
谢谢大家!
推荐答案
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()
这篇关于NetworkX-在图上查找点的自然簇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!