【问题标题】:Convert to directed graph to undirected graph in Python igraph在Python igraph中将有向图转换为无向图
【发布时间】:2016-06-10 20:09:26
【问题描述】:

我正在尝试在 iGraph 中绘制无向图,但我绘制的图上似乎仍有小箭头。是否可以将有向图对象转换为无向图对象,从而使箭头消失?

这是我的代码:

import igraph
import cairo
import igraph
graph = igraph.Graph.Read_Ncol('network.txt')
igraph.plot(graph)

network.txt =

1 2
2 1
2 3
2 7
3 1
4 2
4 6
5 4
5 6
7 4
7 8
8 9
9 7
10 7
10 8
10 9
11 2
1 2
3 4
5 8
12 3
1 1

【问题讨论】:

  • Graph.Read_Ncol() 有一个 directed=... 关键字参数,让 igraph 知道您正在加载的图形是有向还是无向(因为 NCOL 格式没有指定它)。

标签: python graph-theory igraph


【解决方案1】:

如此处所述:http://igraph.org/python/doc/igraph.GraphBase-class.html

有功能:

to_directed()
to_undirected()

取决于你想走哪条路(从标题我看不清楚)。

【讨论】:

  • 我认为这会打乱一些顶点和边的标签。最好使用@Tamás 提到的关键字导入它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 2011-09-17
  • 2017-01-18
相关资源
最近更新 更多