這裏是我的代碼:圖形工具ValueError異常與graph_union用於過濾圖
import graph_tool.all as gt
print gt.__version__
g1 = gt.Graph()
g1.add_vertex(5)
g1.add_edge_list([(0,1),(1,2),(2,3),(3,4)])
g2 = gt.Graph()
#g2.add_vertex(3)
#g2.add_edge_list([(0,1),(1,2)])
g1.vp['prop'] = g1.new_vp('int', 1)
g1.ep['eprop'] = g1.new_ep('bool', False)
g1.ep['eprop'][list(g1.edges())[0]]=True
g1.set_edge_filter(g1.ep['eprop'], inverted=True)
#g2.vp['prop'] = g2.new_vp('int', 2)
ug = gt.graph_union(g1, g2, intersection = None, include = True, internal_props=True)
print ug
ug.list_properties()
for e in ug.edges():
print e, ug.ep['eprop'][e]
我得到以下輸出:
2.20 (commit f6ef9990, Fri Jan 27 16:40:08 2017 +0000)
Traceback (most recent call last):
File "Untitled.py", line 17, in
ug = gt.graph_union(g1, g2, intersection = None, include = True, internal_props=True)
File "/usr/local/lib/python2.7/site-packages/graph_tool/generation/init.py", line 1192, in graph_union vmask.a = not vmask.a
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我想這可能是類似於this bug的錯誤,特別是在gt.generation__init__.py
行1185有錯誤修復:emask.a = numpy.logical_not(emask.a)
,而行1192有舊vmask.a = not vmask.a
。任何人都可以確認這是一個錯誤還是我做錯了什麼?