Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

networkx edge-to-node node-to-edge representation

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

Now let us imagine an alternative representation of this graph G'(e'=v,v'=e), that is the nodes v' in G' are actually the edges in the graph G, keeping the connectivity the same. Now its distance matrix, D' is MxM.

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

like image 431
Asif Rehan Avatar asked May 06 '15 03:05

Asif Rehan


People also ask

What is Nbunch in NetworkX?

nbunch. An nbunch is a single node, container of nodes or None (representing all nodes). It can be a list, set, graph, etc.. To filter an nbunch so that only nodes actually in G appear, use G.

How do I display a graph in NetworkX?

Draw the graph G using Matplotlib. Draw the nodes of the graph G. Draw the edges of the graph G. Draw node labels on the graph G.

What is the difference between edge and node?

The nodes represent different entities (e.g. proteins or genes in biological networks), and edges convey information about the links between the nodes.


1 Answers

networkx has a function called line_graph() that appears to do what you're looking for. Here is 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

like image 131
Scott Avatar answered Oct 11 '22 13:10

Scott