networkx边缘到节点的节点到边缘表示 [英] networkx edge-to-node node-to-edge representation

查看:91
本文介绍了networkx边缘到节点的节点到边缘表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个具有N个节点和M个边的图形G(e,v).它的距离矩阵D是一个NxN矩阵.

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

现在让我们想象一下该图G'(e'=v,v'=e)的另一种表示形式,即G'中的节点v'实际上是图G中的边,保持了连通性不变.现在它的距离矩阵D'是MxM.

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.

NetworkX中是否已有任何方法可以从D(NxN)获取此D'(MxM)?

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

推荐答案

networkx具有一个称为

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

这篇关于networkx边缘到节点的节点到边缘表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆