PyDocs

Nav

Numeric and Mathematical Modules

harmonic_mean

statistics

function · Added in 3.6 (source)
  • harmonic_mean(data, weights=None)
Return the harmonic mean of data.

The harmonic mean is the reciprocal of the arithmetic mean of the
reciprocals of the data.  It can be used for averaging ratios or
rates, for example speeds.

Suppose a car travels 40 km/hr for 5 km and then speeds-up to
60 km/hr for another 5 km. What is the average speed?

    >>> harmonic_mean([40, 60])
    48.0

Suppose a car travels 40 km/hr for 5 km, and when traffic clears,
speeds-up to 60 km/hr for the remaining 30 km of the journey. What
is the average speed?

    >>> harmonic_mean([40, 60], weights=[5, 30])
    56.0

If ``data`` is empty, or any element is less than zero,
``harmonic_mean`` will raise ``StatisticsError``.
Changed in 3.10
  • 3.10: Added support for weights.
1 Example
>>> harmonic_mean([40, 60])
48.0
from the Python docs
See Also
No see-alsos for statistics/harmonic_mean
0 Notes
No notes for harmonic_mean