【发布时间】:2019-11-23 03:23:28
【问题描述】:
我在 Python 3 中有这个简单的代码,它使用 igraph 返回我添加到无向图中的边。
from igraph import *
g = Graph()
g.add_vertices(3)
g.add_edges([(0,1), (1,2)])
# display(plot(g))
edge=g.es.find(_source=1, _target=0)
但是当我使用函数 graph.es.find() 时,它给了我一个错误,而不是返回边缘。它说“没有这样的优势”。
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-14-4182287b1986> in <module>
4 g.add_edges([(0,1), (1,2)])
5 # display(plot(g))
----> 6 edge=g.es.find(_source=1, _target=0)
E:\Softwares\Anaconda\lib\site-packages\igraph\__init__.py in find(self, *args, **kwds)
3615 if es:
3616 return es[0]
-> 3617 raise ValueError("no such edge")
3618
3619 def select(self, *args, **kwds):
ValueError: no such edge
但是,如果我按照输入的顺序设置源和目标,它确实会返回边缘。在这种情况下,源 = 0,目标 = 1
我的猜测是它并不是一个真正的无向图。
我的问题是,即使我在 g.es.find() 函数中切换源节点和目标节点,我如何获得一个返回边的真正无向图,因为它应该是无向图?
【问题讨论】:
标签: graph igraph python-3.7 undirected-graph