To add edges with weights to a newtorkx digraph, you can use the add_weighted_edges_from() method. Here's an example code snippet:
main.py175 chars10 lines
In the above code, we first create a new directed graph G. We then add three edges (0,1), (1,2), (2,3) with weights 0.5, 0.75, and 1.2, respectively, using the add_weighted_edges_from() method. Finally, we print the graph using the edges() method with the data=True argument to display the weights of the edges.
Output:
main.py79 chars4 lines
gistlibby LogSnag