Statistics Functions

statistics.harmonic_mean()

Calculate the reciprocal of the average reciprocal, optionally weighted. Useful for rates over equal distances. Negative inputs are invalid; a zero can cause an early zero result without validating later items. Weights should be nonnegative with positive total.

Formal Syntax & Structure

python syntaxpython
statistics.harmonic_mean(data, weights=None)

Parameters & Attributes

NameTypeDescription
dataiterable of numbersObservations used by the statistic.
weightsiterable of numbers or NoneOptional weights, one per observation.

Return Value

number

Numeric result; concrete type depends on inputs.

Working Example

Example Snippetpython
import statisticsprint(statistics.harmonic_mean([30, 60]))
Python Reference