【发布时间】:2019-07-15 09:18:28
【问题描述】:
我有一个Graph 和一个关联的边缘属性。然后我使用带有GraphView 的顶点过滤器过滤图形。
g = Graph(directed=False)
g.add_vertex(6)
g.add_edge_list([(0, 1), (1, 2), (1, 4), (2, 4), (3, 5), (4, 5)])
eprop = g.new_edge_property('int')
eprop.a = numpy.random.randint(0, 10, g.num_edges())
vfilt = g.new_vertex_property('bool')
vfilt.a[[0, 1, 2, 4]] = True
h = GraphView(g, vfilt=vfilt)
在这个例子中,原始图有 6 个顶点和 6 个边,正如预期的那样。
<Graph object, undirected, with 6 vertices and 6 edges at 0x1f9149550>
视图有 4 个顶点和 4 个边。
<GraphView object, undirected, with 4 vertices and 4 edges, edges filtered by (<PropertyMap object with key type 'Edge' and value type 'bool', for Graph 0x209b4f7f0, at 0x182ea70f0>, False), vertices filtered by (<PropertyMap object with key type 'Vertex' and value type 'bool', for Graph 0x209b4f7f0, at 0x14a00a710>, False) at 0x209b4f7f0>
我的最终目标是为存在于h 中的边获取eprop 的值。一种简单快捷的方法是在eprop.a 上使用布尔数组索引。我以为我可以为此使用视图的边缘过滤器,但它的行为不像我预期的那样。
h.get_edge_filter() 返回一个PropertyMap
(<PropertyMap object with key type 'Edge' and value type 'bool', for Graph 0x209b4f7f0, at 0x182ea70f0>,
False)
但是h.get_edge_filter()[0].a显示所有值都是True
PropertyArray([1, 1, 1, 1, 1, 1], dtype=uint8)
我是在做错事还是期待我不应该做的事情?
有没有更快的方法来获取一组顶点之间所有边的边属性值?
【问题讨论】:
标签: python graph-tool