networkx.algorithms.distance_measures.barycenter¶
-
barycenter(G, weight=None, attr=None, sp=None)[source]¶ Calculate barycenter of a connected graph, optionally with edge weights.
The barycenter a
connectedgraph \(G\) is the subgraph induced by the set of its nodes \(v\) minimizing the objective function\[\sum_{u \in V(G)} d_G(u, v),\]where \(d_G\) is the (possibly weighted)
path length. The barycenter is also called the median. See [West01], p. 78.- Parameters
G (
networkx.Graph) – The connected graph \(G\).weight (
str, optional) – Passed through toshortest_path_length().attr (
str, optional) – If given, write the value of the objective function to each node’sattrattribute. Otherwise do not store the value.sp (dict of dicts, optional) – All pairs shortest path lengths as a dictionary of dictionaries
- Returns
Nodes of
Gthat induce the barycenter ofG.- Return type
- Raises
NetworkXNoPath – If
Gis disconnected.Gmay appear disconnected tobarycenter()ifspis given but is missing shortest path lengths for any pairs.ValueError – If
spandweightare both given.
See also