Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change individual vertex attributes in python igraph

For a given graph g I cannot change an individual vertex attribute (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 doing so, print g.vs['color'] still gives

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

How can I assign values for individual items?

like image 664
flonk Avatar asked Jan 22 '14 15:01

flonk


Video Answer


1 Answers

You're just doing it backwards... do

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

sorry, should be more descriptive.

g.vs['color'] returns a list of all the node attributes. These aren't the actual attributes - it's a copy, so modifying it has no effect.

g.vs[0] returns the actual vertex 0. You can then modify its attributes using the dictionary interface.

like image 80
Corley Brigman Avatar answered Oct 23 '22 03:10

Corley Brigman