To add parameter to existing edges in a Networkx graph, you can use the set_edge_attributes()
function. This function sets one or more parameters of the edge.
Here's an example:
main.py354 chars18 lines
Output:
main.py55 chars2 lines
In the params
dictionary, the keys are tuples representing edges and the values are dictionaries of parameters to set for the edges. The set_edge_attributes()
function takes two arguments: the graph and the dictionary of parameters.
This will set the weight
parameter to 3 for the edge ('A', 'B') and 5 for the edge ('B', 'C').
Note that you can also use the add_edge()
function to add new edges with parameters directly.
gistlibby LogSnag