Home > AI > Uncategorized

networkx-connected_components

This function return the group of all connected edges. The code is here:

import networkx as nx

graph = nx.Graph()

graph.add_edge(5, 3)
graph.add_edge(3, 5)

graph.add_edge(1, 2)
graph.add_edge(2, 1)
graph.add_edge(2, 4)
graph.add_edge(4, 2)

a = list(list(x) for x in nx.connected_components(graph))
a

Here is the diagram

Related posts:

Leave a Reply