statistics.harmonic_mean
Prev: statistics.geometric_mean | Up: statistics | Next: statistics.kde
Rel: statistics.correlation, statistics.covariance, statistics.fmean, statistics.geometric_mean
Ref: docs.python.org — statistics.harmonic_mean
Tags: #public #python3 #stdlib #statistics
Import
import statistics
from statistics import harmonic_mean
Signature & Overview
statistics.harmonic_mean(data, weights=None)
Return the harmonic mean of data.
Usage
import statistics
# Average speed over equal distances (40 mph out, 60 mph back -> 48 mph)
assert round(statistics.harmonic_mean([40, 60]), 6) == 48.0
Gotchas
- Best average for rates/ratios: Negative values raise
StatisticsError; any0returns0.
REPL Inspect
from statistics import harmonic_mean
help(harmonic_mean)
Linked from
Related notes
- tuts/python3/stdlib_module/statistics/correlation Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/covariance Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/fmean Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/geometric_mean Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/kde Linked here; links to this page; shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/statistics/kde_random shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/linear_regression shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/mean shared tags: #statistics, #stdlib
- tuts/python3/stdlib_module/statistics/median shared tags: #statistics, #stdlib