Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

igraph: how to use add_edges when there are attributes?

Tags:

python

igraph

What if I need to create a graph in igraph and add a bunch of edges, but the edges have associated attributes? It looks like .add_edges can only take a list of edges without attributes, so I've been adding them one by one with .add_edge

like image 453
user1919878 Avatar asked Dec 20 '12 19:12

user1919878


2 Answers

graph.add_edge('A','B',weight = 20)

Here A and B are names of nodes

like image 152
Kush Jain Avatar answered Nov 18 '22 14:11

Kush Jain


You can assign the attributes later; e.g.:

graph.es["weight"] = range(g.ecount())

This will assign weights to all the edges at once. If you want to assign attributes to only a subset of the edges, index or slice the edge sequence (g.es) in however you want:

graph.es[10:20]["weight"] = range(10)
like image 28
Tamás Avatar answered Nov 18 '22 15:11

Tamás