Return the average shortest path length.
The average shortest path length is
where is the set of nodes in , is the shortest path from to , and is the number of nodes in .
Parameters : | G : NetworkX graph weight : None or string, optional (default = None)
|
---|---|
Raises : | NetworkXError: :
|
Examples
>>> G=nx.path_graph(5)
>>> print(nx.average_shortest_path_length(G))
2.0
For disconnected graphs you can compute the average shortest path length for each component: >>> G=nx.Graph([(1,2),(3,4)]) >>> for g in nx.connected_component_subgraphs(G): ... print(nx.average_shortest_path_length(g)) 1.0 1.0