Accessing the internal array of vector property maps
Hello world! Property maps are really useful and I've come to love them! However, sometimes it's handy to convert them back to arrays (for example for plotting). For vertex property maps that are scalar valued, we have the handy shortcut `.a` or the method `.get_array()`. However, these do not seem to work for vector valued vp's. Say for example that I'm storing the 2D coordinates of the vertices inside the vp `pos`. `g.vp.pos.a` returns `None`, and the way I typically convert this to an array is ``` print(g.vp.pos) # <VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f02f04d34f0, at 0x7f0297d164f0> pos = np.array(list(g.vp.pos)) print(pos.shape) # (100, 2) ``` but I wonder if there is a better way to do this. What do other people use in this case? Rodrigo
Am 29.03.21 um 15:53 schrieb Rodrigo Leal Cervantes:
Say for example that I'm storing the 2D coordinates of the vertices inside the vp `pos`. `g.vp.pos.a` returns `None`, and the way I typically convert this to an array is
``` print(g.vp.pos) # <VertexPropertyMap object with value type 'vector<double>', for Graph 0x7f02f04d34f0, at 0x7f0297d164f0>
pos = np.array(list(g.vp.pos)) print(pos.shape) # (100, 2) ```
but I wonder if there is a better way to do this. What do other people use in this case?
Yes, take a look at: https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.PropertyM... This means you can do: a = g.vp.pos.get_2d_array([0, 1]) The reason why this is needed is because vector properties are *not* internally stored as contiguous 2D arrays. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
Rodrigo Leal Cervantes -
Tiago de Paula Peixoto