0

I have a Graph and an associated edge property. I then filter the graph with a vertex filter with a 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)

In this example, the original graph has 6 vertices and 6 edges as expected.

<Graph object, undirected, with 6 vertices and 6 edges at 0x1f9149550>

The view has 4 vertices and 4 edges.

<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>

My ultimate objective is to get the values of eprop for the edges that exist in h. An easy and quick way to do this would be to use boolean array indexing on eprop.a. I thought that I would be able to use the view's edge filter for this, but it doesn't behave as I expected.

h.get_edge_filter() returns a PropertyMap

(<PropertyMap object with key type 'Edge' and value type 'bool', for Graph 0x209b4f7f0, at 0x182ea70f0>,
 False)

but h.get_edge_filter()[0].a shows that all the values are True

PropertyArray([1, 1, 1, 1, 1, 1], dtype=uint8)

Am I doing something wrong here or expecting behaviour that I shouldn't?

Is there a faster way to get the edge property values for all the edges between a set of vertices?

maxcalibur
  • 43
  • 8

1 Answers1

1

The behavior is expected for filtered graphs. The .a attribute always returns the underlying array, which contains also the unfiltered values. To access only the filtered values, you should use the .fa attribute instead.

This is explained in the documentation here: https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.PropertyMap.fa

Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28