3
votes

I am looking into converting some code from Python NetworkX to Python-IGraph. When adding nodes and edges to a graph, NetworkX very easily allows you to do: g.add_node(a[0], n=a[1]) where a[0] is the node label and a[1] is the value of the attribute "n". How can we add attributes to a node and similarly to an edge, when creating them with Python-IGraph? Thank you!

1

1 Answers

2
votes

Welcome to Stack Overflow! What you're looking for is here (edges and vertices). Here's the overview:

To add an edge or vertex with an attribute:

g.add_edge(source, target, some_attribute=some_value)

g.add_vertex(name, some_attribute=some_value)