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)?
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.
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.
The nodes represent different entities (e.g. proteins or genes in biological networks), and edges convey information about the links between the nodes.
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()
nx.draw(L, node_size=500)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With