def get_directed_component_subgraphs(G):
"""
Find disconnected subgraphs from original graph and add them to one array
"""
subgraphs = []
undirected = G.to_undirected()
for node in G.nodes():
copy = G.subgraph(nx.shortest_path(undirected, node)).copy()
G.remove_nodes_from(copy.nodes())
subgraphs.append(copy)
print len(G), '\n'
return subgraphs
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to networkx-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.
You must be looking for nx.connected_components or nx.connected_component_subgraphs (they actually do the same thing, but return either graphs themselves or node lists).
On Fri, Aug 18, 2017 at 2:07 PM, Peter Bočan <peppy...@gmail.com> wrote:
Hello guys,
I have an issue that I cant deal with by myself, so I am asking you, as experienced with this library. I have a DiGraph G, which consists of many disconnected digraphs (some of them have cycles) and I want those directed subgraphs separated and put into an array. I tried this code but it does not work, because I get from 18000 nodes of G, to 18000 subgraphs... no idea why though.def get_directed_component_subgraphs(G):
"""
Find disconnected subgraphs from original graph and add them to one array
"""
subgraphs = []
undirected = G.to_undirected()
for node in G.nodes():
copy = G.subgraph(nx.shortest_path(undirected, node)).copy()
G.remove_nodes_from(copy.nodes())
subgraphs.append(copy)
print len(G), '\n'
return subgraphsAny idea?
Thanks.
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.