Thanks Tiago!

Let me just point out that the part

  mask.a = g.degree_property_map("out").a > 4

will (if you are using python 2.x) not give you what you most likely would like to have, namely a list of boolean values containing the results of the element wise comparisons of elements g.degree_property_map("out").a[i]>4. Instead, for some strange reason, you'll simply get the *value* True back, writing True to all elements in mask.a ... instead, it seems to me, the only (fastest) way to do it is to use map

  mask.a = map(lambda(x): x > 4, g.degree_property_map("out").a)
.... so be careful. 


On 30 September 2013 16:13, Tiago de Paula Peixoto <> wrote:
Hi René,

On 09/30/2013 03:57 PM, Rene Pfitzner wrote:
> Hi everyone,
> this might be easily solved, but anyways:
> I have been thinking whether there is a fast way of retrieving
> property map values of subsets of nodes? I mean the following: let's
> say I have a property map A, defined for all vertices of graph G. Now,
> lets say I have a vertex iterator V that spans a subset of all nodes
> of G. Is there now a fast way, to a) read and b) eventually change the
> values in A of all nodes in V, e.g. to do something like A[V] and to
> get an array back, like in A.a ....
> Of course, iterating or map would be obvious options, but take
> eventually a lot of time. Another idea I had was, let's say the
> property map is an internal property map, to use vertex_filter and
> then get A.a. But what if the property map is not internal?

This is easily done with graph filters, as you suggest. It does not
matter whether or not the property maps are internal.

For instance, suppose you want to modify the property of all nodes with
a degree larger than four. You could do:

  g = ... # this is your graph
  prop = ... # this is your property

  mask = g.new_vertex_property("bool")
  mask.a = g.degree_property_map("out").a > 4

  prop.fa = 42   # this only affects the filtered values

You can also do it using a graph view:

  u = GraphView(g, vfilt=g.degree_property_map("out").a > 4)
  uprop = u.own_property(prop)
  uprop.fa = 42

I prefer the last one, since it is more compact.

(Note the use of A.fa instead of A.a)


Tiago de Paula Peixoto <>

René Pfitzner, Dipl. Phys.
Scientific assistant / Doctoral candidate

ETH Zürich
Chair of Systems Design