且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-26 15:46:12

     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()