问题
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)?
回答1:
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()

来源:https://stackoverflow.com/questions/30066788/networkx-edge-to-node-node-to-edge-representation