Reputation: 3876
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?
Upvotes: 8
Views: 3975
Reputation: 12371
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.
Upvotes: 7