Hi again,

I'm using boolean PropertyMaps to represent subsets of graph vertices
in combination with `GraphView(g, vfilt=Mask).vertices()` for iteration.
I often need the complement of such sets and would like to complement
a mask using `numpy.invert`, for efficiency:

"""
Mask = graph.new_vertex_property('bool')

# this fails
import numpy
notm = numpy.invert(M.ma)
NotMask = graph.new_vertex_property('bool', vals=notm)

# this works, but is O(|V|)
it = imap(lambda x:not Mask[x], graph.vertices())
NotMask = graph.new_vertex_property("bool", vals=it)
"""

The issue seems to be that in boolean PropertyMap internally
uses a PropertyArray of dtype `uint8`, and not `bool`:
In the example above (my graph has 6 nodes), Mask.ma is

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

So of course, numpy.invert(M.ma) yields

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

and not, as expected, the array with only 1's.

Is there a reason for using uint8 instead of booleans?
And is there a O(1) operation to invert masks?
Thanks,
Patrick
_______________________________________________
graph-tool mailing list
[email protected]
https://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to