How to calculate the harmonic mean

Calculate the harmonic mean H = n/Σ(1/xᵢ): average speeds, P/E ratios, parallel resistances, F1-score. Comparison with arithmetic and geometric mean with verified examples.

Calculation parameters
Was this calculator useful?

How to calculate the harmonic mean lets you find the appropriate average when data represent rates, speeds, frequencies, or ratios. The formula is H = n / Σ(1/xᵢ): the number of elements divided by the sum of reciprocals. The harmonic mean is always ≤ the geometric mean, which is ≤ the arithmetic mean (HM-GM-AM inequality, Cauchy 1821). It is used for speeds with equal distances, aggregated P/E ratios, parallel resistances, F1-scores in machine learning, and averaging growth rates, per NIST Engineering Statistics Handbook standards.

Formula and definition

Given n positive observations x₁, x₂, ..., xₙ, the harmonic mean is: H = n / (1/x₁ + 1/x₂ + ... + 1/xₙ). For two values it simplifies to H = 2x₁x₂ / (x₁ + x₂). For the weighted version: H = Σwᵢ / Σ(wᵢ/xᵢ), where wᵢ are weights, used by US Census Bureau and Federal Reserve.

The HM ≤ GM ≤ AM inequality always holds, with equality only if all values are identical. For two values 40 and 60: H = 48, G = √(40·60) = 48.99, A = 50. The HM-AM gap grows with value dispersion; for identical data (50, 50) all means coincide. Derivation follows from Hardy-Littlewood-Pólya generalized means theory (1934), foundational in NIST mathematical statistics.

History and mathematical context

The harmonic mean was studied by the Pythagoreans (6th century BCE) in musical proportion contexts: the 1:1/2:1/3 ratio corresponds to consonant interval frequencies. Archytas of Tarentum (430-360 BCE) defined it as the "third mean" after arithmetic and geometric. The term "harmonia" derives from musical chord harmony. Cauchy (Cours d'Analyse, 1821) and Schwarz rigorously proved the HM ≤ GM ≤ AM inequality.

In modern applications, NIST uses harmonic mean in measurement statistics. NHS uses it for healthcare cost aggregation. The F1-score in machine learning is a harmonic mean of precision and recall (lowering one automatically lowers F1). The CDC applies it for outbreak rate aggregation, FDA for drug efficacy ratios, and the SEC for portfolio P/E aggregation. NASA also uses it for averaging satellite velocity components.

Comparison table arithmetic/geometric/harmonic means

ValuesArithmeticGeometricHarmonicAM-HM gap
10, 1010.0010.0010.000%
40, 6050.0048.9948.004%
1, 10050.5010.001.9896%
2, 4, 84.674.003.4327%
5, 10, 15, 2012.5010.619.0727%
30, 50, 70, 9060.0056.1252.0313%
0.1, 0.5, 1, 51.650.710.3082%

Means converge for similar values and diverge significantly for dispersed values. The harmonic mean is particularly sensitive to small values, hence its use when small values dominate (parallel resistors, long times).

5 verified numerical examples

  1. Average speed at equal distance: outbound 60 mph and return 100 mph on same route. Average speed = H(60, 100) = 2·60·100/(60+100) = 75 mph, NOT 80 (common AM error).
  2. Parallel resistors: three resistors 10Ω, 20Ω, 30Ω. R_eq = 1/(1/10 + 1/20 + 1/30) = 5.455Ω. Standard IEEE 1241-2010.
  3. Aggregated portfolio P/E: 3 stocks with P/E 15, 25, 50. Harmonic mean = 3/(1/15 + 1/25 + 1/50) = 22.06; arithmetic = 30.00. The harmonic better reflects aggregate earnings yield (total EPS/Price).
  4. F1-score machine learning: precision 0.80 and recall 0.60. F1 = 2·0.80·0.60/(0.80+0.60) = 0.686. Penalizes the low recall value more than AM (0.70). Standard scikit-learn library.
  5. Average task completion time: 4 machines complete in 3, 4, 5, 6 hours. Harmonic average time = 4/(1/3+1/4+1/5+1/6) = 4.11 hours. Reflects the effective "average" machine considering completion rates (1/time).

Model limitations

Three main limits to harmonic mean usage:

  • Doesn't work with zero or negative values: division 1/0 is undefined; negative values give paradoxical results. For mixed positive/negative data use arithmetic mean or transform data (e.g., absolute values), per NIST Statistical Engineering Handbook.
  • Small outlier sensitivity: a value near zero dominates the mean, similar to a short-circuit. Example: H(1, 100, 100) = 2.97 vs A = 67. A single small value drastically reduces harmonic mean.
  • Contextual interpretation: use HM only when data are rates or ratios with a constant physical denominator. For additive quantities (weights, monetary amounts, counts) arithmetic mean is correct.

Common errors

  • Using AM for speeds: at equal distances but different times, average speed is harmonic, not arithmetic. Common in physics homework.
  • F1-score with AM: F1 must be harmonic to penalize unbalanced classifiers; AM would show false optimism.
  • Index P/E mean: indices (S&P 500, FTSE 100) use aggregate P/E (sum earnings / sum prices), a weighted harmonic mean.
  • Network speed calculation: bandwidth in series is harmonic; parallel is sum. Common error in enterprise network sizing per Cisco design guides.
  • Average density: for mixtures at equal volume use AM; equal mass use HM. Frequent error in chemistry and ASTM E12 density standards.
  • Productivity indices: average time per unit is harmonic if units are equal (e.g., machines), arithmetic if different (e.g., labor-hours).

Numbered practical applications

  1. Round-trip average speed: 100 mi at 80 mph and 100 mi at 50 mph. H = 2·80·50/(80+50) = 61.5 mph.
  2. Parallel resistors electronics: voltage divider design with 100Ω, 220Ω, 470Ω: R_eq = 56.5Ω. Standard IEEE/IEC 60063.
  3. F1-score ML models: classifier evaluation with precision 0.75 and recall 0.90: F1 = 0.818. Standard scikit-learn and TensorFlow.
  4. P/E ratio index funds: ETF with stocks at P/E 12, 18, 25, 40: aggregate harmonic P/E = 19.1 (vs arithmetic 23.75). Reflects index earnings yield.
  5. Composite alloy density: alloys at equal mass, average density = HM of individual ρ. Stainless steel AISI 304 ρ = 8.0 g/cm³, ASTM A240.
  6. Series capacitors: 3 capacitors 10μF, 22μF, 47μF in series: C_eq = 1/(1/10+1/22+1/47) = 5.82μF. IEC 60384 standard.
  7. Composite thermal conductivity: layered wall perpendicular to flow → HM. ISO 6946 thermal insulation standard for buildings.

For technical support: info@calcoi.com.

Updated July 2026

Frequently Asked Questions

What is the difference between arithmetic and harmonic mean?

Arithmetic sums values and divides by n: AM = Σx/n. Harmonic uses reciprocals: HM = n/Σ(1/x). For values 40 and 60: AM = 50, HM = 48. Harmonic is always smaller than arithmetic for non-identical positive data (Cauchy inequality 1821). HM is appropriate for rates and ratios with constant denominator (speeds, frequencies).

When to use the harmonic mean?

Use HM when data are rates (mph, ms/operation, Hz frequencies) and the denominator quantity is constant. Examples: average speed at equal distance, aggregated P/E ratios, parallel resistors, F1-score in ML, average task completion times. For additive quantities ($, kg, people) use arithmetic mean instead, per NIST guidelines.

How to calculate harmonic mean of two numbers?

For two values a and b: HM = 2ab / (a + b). Example: HM(40, 60) = 2·40·60 / (40+60) = 4800/100 = 48. This closed-form formula avoids reciprocal calculation and is useful for two-element problems like round-trip speed or two-resistor parallel circuits per IEEE Std 1241.

Why is average speed harmonic?

For paths at equal distance, total time is t1 + t2 = d/v1 + d/v2. Average speed = 2d / (d/v1 + d/v2) = 2 / (1/v1 + 1/v2) = HM(v1, v2). Example: 60 mph outbound and 100 mph return → 75 mph, not 80 (AM). At average AM of 80 mph would require equal times, not equal distances. Standard physics result per NIST measurement guide.

Is F1-score really a harmonic mean?

Yes: F1 = 2·P·R / (P+R) = HM(P, R). Penalizes unbalanced classifiers: with precision 1.0 and recall 0.1, AM gives 0.55 (optimistic), while F1 = 0.182 reflects true poor performance. Standard sklearn.metrics.f1_score, ML benchmarks ImageNet/COCO. F-beta variant weights β² to recall: F2 emphasizes recall, F0.5 emphasizes precision.

What if one value is zero?

Harmonic mean becomes undefined (1/0 doesn't exist). Software returns error or NaN. To avoid: filter zeros or replace with small values. Physical interpretation: in a parallel circuit, if one resistor is zero (short-circuit), equivalent resistance is zero, consistent with HM→0 limit when one value approaches zero per IEEE Std 1241-2010.

Why HM ≤ GM ≤ AM?

Inequality proved by Cauchy (1821) and generalized by Hardy-Littlewood-Pólya (1934). For two values a, b: AM = (a+b)/2, GM = √(ab), HM = 2ab/(a+b). Holds (a-b)² ≥ 0 → a²+b² ≥ 2ab → AM ≥ GM. Similarly GM² = ab ≥ 2ab/(a+b)·HM ≥ HM². Equality only if a=b. Implication: HM rewards uniformity, foundational result in NIST statistics.

Formula

H = \frac{n}{\sum_{i=1}^{n}{1/x_i}}

Comments (0)

No comments yet. Be the first!