Changing individual vertex attributes in python igraph

For a given graph g I cannot change the attribute of a single vertex (in this case, 'color' ):

 from igraph import Graph # create triangle graph g = Graph.Full(3) cl_blue = (0,0,.5) cl_red = (.5,0,0) g.vs['color'] = 3*[cl_blue] g.vs['color'][0] = cl_red 

after that print g.vs['color'] still gives

 [(0, 0, 0.5), (0, 0, 0.5), (0, 0, 0.5)] 

How to assign values ​​to individual elements?

+7
python list igraph
source share
1 answer

You just do it back ... do

 g.vs[0]['color'] = cl_red 

Sorry, should be more descriptive.

g.vs['color'] returns a list of all node attributes. These are not actual attributes - this is a copy, so changing it has no effect.

g.vs[0] returns the actual vertex 0. Then you can change its attributes using the dictionary interface.

+6
source share

All Articles