Harmonic Mean Calculator

Average rates the way the physics actually works: the harmonic mean is the correct average for speeds over equal distances, prices per fixed budget, and any quantity where reciprocals — not the values themselves — are what add up. The calculator reports all three classical means side by side so you can see the AM ≥ GM ≥ HM chain on your own data.

When to Reach for the Harmonic Mean

  • Speeds over equal distances: a round trip driven at two different speeds, laps of a track, legs of a route.
  • Cost averaging: spending a fixed amount per month on shares at varying prices — the average price paid is the harmonic mean.
  • Combined rates and ratios: parallel resistors, aggregated P/E ratios, and the F1 score in machine learning.

Data Requirements

Every value must be strictly positive: zero has no reciprocal, and a mix of positive and negative rates makes the reciprocal sum meaningless. The calculator reports any offending values instead of silently skipping them.

Because small values dominate the reciprocal sum, one tiny entry pulls the harmonic mean down hard — double-check suspiciously small inputs before trusting the result.

Enter numbers separated by commas, spaces, or line breaks

The Formula: Reciprocals In, Reciprocal Out

The harmonic mean flips every value, averages the flips, and flips back:

HM = n / (1/x₁ + 1/x₂ + … + 1/xₙ)

For two values: HM = 2ab / (a + b)

The structure explains the behavior. Because each value enters as a reciprocal, small values contribute large terms to the sum in the denominator and therefore dominate the result. An arithmetic mean is pulled up by one huge value; a harmonic mean is pulled down by one tiny value. Whichever quantity genuinely accumulates in your problem — hours per kilometer, dollars per share, errors per prediction — is the one that should be averaged directly, and the harmonic mean is what you get when that accumulating quantity is the reciprocal of what you are quoting.

Why Averaging Rates Needs the Harmonic Mean

Speed is distance over time. When the distances of two trip legs are equal, the slow leg takes more time than the fast leg, so the slow speed governs a larger share of the journey. Averaging the two speed numbers arithmetically weights each leg by count instead of by time, which overstates the true average. Dividing total distance by total time — the definition of average speed — collapses algebraically to exactly the harmonic mean of the leg speeds whenever the distances match.

The same logic covers any "per" quantity with a fixed numerator or denominator: pages per hour when each session covers the same number of pages, fuel consumption over identical routes, download speeds for files of the same size. When the legs are not equal, the right tool is a weighted harmonic mean with the distances as weights — the plain version this calculator computes assumes equal weighting.

P/E Ratios and the F1 Score

Two famous applications live far from the highway. In finance, the average price-to-earnings ratio of a portfolio is computed harmonically: P/E has price on top, so a stock with enormous P/E (tiny earnings) would explode an arithmetic average while contributing almost nothing to real earning power. The harmonic mean weights each holding by the earnings a dollar of investment actually buys, matching the portfolio-level ratio of total price to total earnings.

In machine learning, the F1 score is the harmonic mean of precision and recall: F1 = 2PR / (P + R). The harmonic mean is chosen deliberately for its harshness — a classifier with precision 1.0 but recall 0.1 gets an F1 near 0.18, not the flattering 0.55 an arithmetic average would report. A model cannot buy a good F1 score by maximizing one metric and abandoning the other.

The AM–GM–HM Chain

For any set of positive numbers that are not all identical, the three classical means line up in strict order:

AM ≥ GM ≥ HM, with equality only when all values are equal

The harmonic mean is always the most conservative of the three and the most sensitive to small values. A useful mnemonic ties each mean to its arithmetic: add values for the arithmetic mean, multiply them for the geometric mean, and add their reciprocals for the harmonic mean. For plain measurements rather than rates, the ordinary average from the mean, median, mode calculator remains the right default.

Worked Example: The Round Trip That Is Not 50 km/h

You drive to a city 120 km away at 60 km/h and return over the same road at 40 km/h. Intuition says the average speed is (60 + 40) ÷ 2 = 50 km/h. The clock disagrees:

  1. Outbound time: 120 ÷ 60 = 2 hours.
  2. Return time: 120 ÷ 40 = 3 hours.
  3. Total: 240 km in 5 hours, so the true average speed is 240 ÷ 5 = 48 km/h.
  4. Harmonic mean check: HM = 2 ÷ (1/60 + 1/40) = 2 × 60 × 40 ÷ (60 + 40) = 4800 ÷ 100 = 48.

The arithmetic mean of 50 km/h is wrong because the return leg at 40 km/h occupied 3 of the 5 hours — the slow speed deserves more weight, and the harmonic mean gives it exactly the weight the clock does. For contrast, the geometric mean of 60 and 40 is √2400 ≈ 48.99, landing between the other two just as the AM ≥ GM ≥ HM chain requires: 50 ≥ 48.99 ≥ 48.

Frequently Asked Questions

Why is the harmonic mean always the smallest of the three means?

Because reciprocals weight small values most heavily. Flipping each value makes small numbers large before averaging, so the smallest inputs dominate the sum and drag the final result down. The AM-GM-HM inequality formalizes this: for positive values that are not all equal, the harmonic mean is strictly below the geometric mean, which is strictly below the arithmetic mean.

When is the arithmetic mean of speeds actually correct?

When the legs take equal times rather than cover equal distances. If you drive one hour at 60 km/h and one hour at 40 km/h, you cover 100 km in 2 hours and the true average is exactly 50 km/h - the arithmetic mean. Equal distances make the harmonic mean correct; equal times make the arithmetic mean correct.

What happens if my data contains a zero?

The harmonic mean is undefined, because 1/0 has no value - and the calculator will flag the entry rather than skip it. Conceptually a zero rate means one leg never finishes: a trip segment at 0 km/h takes infinite time, so no finite average speed can describe the journey.

Why do portfolios average P/E ratios harmonically?

Because the meaningful aggregate is total price divided by total earnings. An arithmetic average of P/E ratios lets one stock with near-zero earnings, and hence an enormous ratio, dominate the number. The harmonic mean, weighted by position size, reproduces the portfolio-level P/E exactly and keeps low-earnings outliers from distorting the valuation picture.

Is the F1 score just the harmonic mean of two numbers?

Yes. F1 = 2PR/(P + R) is precisely the two-value harmonic mean formula applied to precision and recall. The harmonic mean is used instead of the arithmetic mean so that a model scoring high on one metric and terribly on the other receives a poor overall score, forcing balanced performance.