efficent way to assign values to vector property map

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

efficent way to assign values to vector property map

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



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: efficent way to assign values to vector property map

Alexandre Hannud Abdo
Ni! Hello Bleak,

I trust two possible solutions to your question stand in plain sight in the sections of the documentation pertaining to property maps.


I'm sure you'll remember to consult it more carefully in the future (=

Cheers,
ale
.~´


On Sat, Jun 13, 2020 at 6:44 PM BleakHeart <[hidden email]> wrote:
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.



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: efficent way to assign values to vector property map

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



--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool
Reply | Threaded
Open this post in threaded view
|

Re: efficent way to assign values to vector property map

Tiago Peixoto
Administrator
Am 14.06.20 um 10:32 schrieb BleakHeart:
> 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?

Not without looping and assiging them one by one.

--
Tiago de Paula Peixoto <[hidden email]>


_______________________________________________
graph-tool mailing list
[hidden email]
https://lists.skewed.de/mailman/listinfo/graph-tool

signature.asc (849 bytes) Download Attachment
--
Tiago de Paula Peixoto <tiago@skewed.de>