Add an edge between u and v with optional data.
The nodes u and v will be automatically added if they are not already in the graph.
Parameters: | u,v : nodes
data : Python object
|
---|
See also
Parallel
Notes
Adding an edge that already exists overwrites the edgedata.
Examples
The following all add the edge e=(1,2) to graph G.
>>> G=nx.Graph()
>>> e=(1,2)
>>> G.add_edge( 1, 2 ) # explicit two node form
>>> G.add_edge( *e) # single edge as tuple of two nodes
>>> G.add_edges_from( [(1,2)] ) # add edges from iterable container
Associate the data myedge to the edge (1,2).
>>> myedge=1.3
>>> G.add_edge(1, 2, myedge)