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


harmonic_centrality(G, nbunch=None, distance=None)[source]

Compute harmonic centrality for nodes.

Harmonic centrality [1] of a node u is the sum of the reciprocal of the shortest path distances from all other nodes to u

\[C(u) = \sum_{v \neq u} \frac{1}{d(v, u)}\]

where d(v, u) is the shortest-path distance between v and u.

Notice that higher values indicate higher centrality.

  • G (graph) – A NetworkX graph
  • nbunch (container) – Container of nodes. If provided harmonic centrality will be computed only over the nodes in nbunch.
  • distance (edge attribute key, optional (default=None)) – Use the specified edge attribute as the edge distance in shortest path calculations. If None, then each edge will have distance equal to 1.

nodes – Dictionary of nodes with harmonic centrality as the value.

Return type:



If the ‘distance’ keyword is set to an edge attribute key then the shortest-path length will be computed using Dijkstra’s algorithm with that edge attribute as the edge weight.


[1]Boldi, Paolo, and Sebastiano Vigna. “Axioms for centrality.” Internet Mathematics 10.3-4 (2014): 222-262.