Hi tiago,
I was thinking if there is an efficient way to assing values to a vector
property map.
The only working method that I can use is the following:
vprop = g.new_vertex_property("vector<double>")
for i in range(G.num_vertices()):
vprop[G.vertex(i)] = [1,2,3]
When I try to use something like this:
index = np.where(some condition on vertex properties)[0]
vprop.a[index] = [1,2,3]
It gives me the error: "TypeError: 'NoneType' object does not support item
assignment".
The error comes only with vector< > type properties.
I am using this to assing colours to some vertices if a given condition is
satified.
I hope that you can help, because the first method is really slow on graphs
with hundred of thousands vertices.
Hi alexandre,
Thank you for the reply. I understood the get_2d_array(), but I am trying to
understand how to use the set_2d_array() in my code.
For example if do:
G = Graph()
G.add_vertex(10)
vprop = G.new_vertex_property("vector<double>")
vprop[G.vertex(1)] = [1,1,0,1]
The vprop.get_2d_array(pos=[0,1,2,3]) gives me an array of shape (4,
G.num_vertices()) where the elements placed in the second column are
[1,1,0,1] and the other elements are zeros.
In my code I will need to assing to specified vertices an array and I can't
understand how to use the pos attribute in the set_2d_array(), because, for
example, if I use set_2d_array(np.array([0.5, 0.2, 0.1, 1]), pos=[0,1,2,3]),
it assigns to each row of the property map an element of the given array.
Is there a way to select the rows and the columns of the property map?
In my code I will need to assing to specified vertices an array and I can't
understand how to use the pos attribute in the set_2d_array(), because, for
example, if I use set_2d_array(np.array([0.5, 0.2, 0.1, 1]), pos=[0,1,2,3]),
it assigns to each row of the property map an element of the given array.
The set_2d_array() method expects a *TWO DIMENSIONAL* array of shape (M,
N), where N is the number of vertices, and M in the size of the property
vector for each vertex.
Is there a way to select the rows and the columns of the property map?