【问题标题】:GraphView edge filter is same as original Graph after vertex filteringGraphView边缘过滤器与顶点过滤后的原始Graph相同
【发布时间】: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


    【解决方案1】:

    过滤图的行为是预期的。 .a 属性始终返回底层数组,其中还包含未过滤的值。要仅访问过滤后的值,您应该改用.fa 属性。

    这在此处的文档中进行了解释:https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.PropertyMap.fa

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 2021-02-01
      相关资源
      最近更新 更多