You can add edges to a graph in networkx
using the .add_edge()
method. Here's an example:
main.py126 chars10 lines
In this example, we first create an empty graph and then add three edges between nodes 1, 2, and 3.
If you want to add multiple edges at once, you can use the .add_edges_from()
method. Here's how:
main.py112 chars6 lines
This will add the same three edges as in the first example, but all at once.
gistlibby LogSnag