我在igraph中有一个图形:
import igraph as ig
vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
但是我想知道在Igraph中是否已经实现了某些功能,以便获得以边为实际g图的节点的图,如下图所示。
答案 0 :(得分:1)
如果我没记错的话,这种转换称为折线图, Igraph python具有函数调用linegraph()。
我相信这就是您想要的。
答案 1 :(得分:0)
就像罗曼说的那样,您可以使用linegraph()
来解决问题。
import igraph as ig
vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
# Graph g with edges as nodes
g = g.linegraph()