def no_connected_components(G): """Returns the number of connected components. Parameters ---------- G : NetworkX graph An undirected graph. Returns ------- n : integer Number of connected components See Also -------- connected_components number_weakly_connected_components number_strongly_connected_components Notes ----- For undirected graphs only. """ return sum(1 for cc in scc(G))
def connected_component_subgraphs(G, copy=True): """Generate connected components as subgraphs. Parameters ---------- G : NetworkX graph An undirected graph. Returns ------- comp : generator A generator of graphs, one for each connected component of G. copy: bool (default=True) If True make a copy of the graph attributes Examples -------- >>> G = nx.path_graph(4) >>> G.add_edge(5,6) >>> graphs = list(nx.connected_component_subgraphs(G)) See Also -------- connected_components Notes ----- For undirected graphs only. Graph, node, and edge attributes are copied to the subgraphs by default. """ for c in scc(G): if copy: yield G.subgraph(c).copy() else: yield G.subgraph(c)
def connected_component_subgraphs(G, copy=True): for c in scc(G): if copy: yield G.subgraph(c).copy() else: yield G.subgraph(c)