Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

number_of_edges

MultiGraph.number_of_edges(u=None, v=None)[source]

Return the number of edges between two nodes.

Parameters:v (u,) – If u and v are specified, return the number of edges between u and v. Otherwise return the total number of all edges.
Returns:nedges – The number of edges in the graph. If nodes u and v are specified return the number of edges between those nodes.
Return type:int

See also

size()

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_path([0,1,2,3])
>>> G.number_of_edges()
3
>>> G.number_of_edges(0,1)
1
>>> e = (0,1)
>>> G.number_of_edges(*e)
1