更新时间: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()