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

自作多情 提交于 2020-08-27 07:16:05

问题


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()

enter image description here

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

enter image description here



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!