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
graph.add_edge('A','B',weight = 20)
Here A and B are names of nodes
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With