GraphView边过滤器与顶点过滤后的原始图相同

2024-09-24 22:19:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Graph和一个相关的edge属性。然后我用一个带有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)

我是做错了什么事,还是期待着我不该做的行为?你知道吗

有没有更快的方法来获取一组顶点之间所有边的边属性值?你知道吗


Tags: andfalseobjecttypewithatgraphbool