average_shortest_path_length#
- graph_tool.structure.average_shortest_path_length(g, weights=None)[git][source]#
Return the average shortest path length between the pairs of vertices.
- Parameters:
- g
Graph Graph to be used.
- weights
EdgePropertyMap(optional, default:None) Edge weights (lengths).
- g
- Returns:
- ell
float The average of \(d(u, v)\) over the ordered pairs of distinct vertices such that \(v\) can be reached from \(u\).
- ell
See also
wiener_indexSum of the distances between all pairs
global_efficiencyAverage inverse distance
graph_tool.stats.distance_histogramDistribution of the distances
Notes
This is the average path length of the graph. Unreachable pairs are excluded from the average, so that the graph need not be connected. The distances are computed with a search from every vertex, in parallel, in time \(O(VE)\) without weights.
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
Examples
>>> g = gt.collection.data["karate"] >>> print(gt.average_shortest_path_length(g)) 2.4081996...