Igraph: how to use add_edges when there are attributes?

What if I need to create a graph in igraph and add a bunch of edges, but the edges have related attributes? It seems that .add_edges can only accept a list of edges without attributes, so I added them one by one using .add_edge

+6
source share
2 answers

You can assign attributes later; eg:.

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

This will assign weights to all ribs at the same time. If you want to assign attributes to only a subset of edges, index or cut the sequence of edges ( g.es ), but you want:

 graph.es[10:20]["weight"] = range(10) 
+5
source
 graph.add_edge('A','B',weight = 20) 

Here A and B are the names of the nodes

+12
source

All Articles