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
| Name | Type | Description |
|---|---|---|
| data | iterable of numbers | Observations used by the statistic. |
| weights | iterable of numbers or None | Optional 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]))