Networkx edge-to-node representation from node to face

There is a graph G (e, v) with N nodes and M edges. Its distance matrix D is an NxN matrix.

Now imagine an alternative representation of this graph G'(e'=v,v'=e)

, that is, the nodes v 'in G' are in fact edges in the graph G, keeping the connectivity the same. Now its distance matrix D 'is equal to MxM.

Is there any way that NetworkX already has to get this D '(MxM) from D (NxN)?

+3


source to share


1 answer


networkx has a line_graph () function , which appears to do what you are looking for. Here's an example of how it works:

import networkx as nx
import matplotlib.pyplot as plt

G=nx.star_graph(3)
L=nx.line_graph(G)
nx.draw(G, node_size=500)
plt.show()

      

enter image description here



nx.draw(L, node_size=500)
plt.show()

      

enter image description here

+2


source







All Articles