Report

Help us improve this tool

Harmonic Mean Calculator

Calculate the harmonic mean of any dataset with step-by-step formulas, comparison with arithmetic and geometric means, and interactive visualization for rates, speeds, and financial analysis.

O M T

What is Harmonic Mean?

The harmonic mean is a type of average calculated as the reciprocal of the arithmetic mean of reciprocals. For a dataset of $n$ positive numbers $x_1, x_2, ..., x_n$, the harmonic mean $H$ is defined as $H = \frac{n}{\sum_{i=1}^{n} \frac{1}{x_i}}$. Unlike the arithmetic mean, the harmonic mean gives greater weight to smaller values, making it particularly useful for averaging rates, ratios, and speeds where the reciprocal relationship is meaningful.

The harmonic mean is always less than or equal to the geometric mean, which is always less than or equal to the arithmetic mean for any set of positive numbers. This fundamental relationship, known as the AM-GM-HM inequality, states that $\text{HM} \leq \text{GM} \leq \text{AM}$, with equality only when all values are identical. For other statistical measures, check out our Geometric Mean Calculator or Statistics Calculator.

The AM-GM-HM Inequality

The three Pythagorean means are related by the inequality $\text{HM} \leq \text{GM} \leq \text{AM}$ for any set of positive numbers. This means the harmonic mean is always the smallest of the three, and the arithmetic mean is always the largest. The differences between these means provide insight into the spread and distribution of the data. When values are tightly clustered, all three means are close together; when values are widely dispersed, the harmonic mean is significantly smaller than the arithmetic mean.

When to Use Harmonic Mean

The harmonic mean is the appropriate choice for averaging rates, ratios, and speeds where the quantities being averaged involve reciprocal relationships. For example, when traveling equal distances at different speeds, the average speed is the harmonic mean of the individual speeds, not the arithmetic mean. This is because you spend more time traveling at the slower speed, so the slower speed has a greater influence on the overall average.

In finance, the harmonic mean is used to calculate average price multiples like P/E ratios for portfolios. In machine learning, the F1 score is the harmonic mean of precision and recall, ensuring both metrics must be reasonably high for a good score. For financial analysis, see our Investment Calculator or CAGR Calculator.

Average Speed Example

If you drive 100 km at 40 km/h and return 100 km at 60 km/h, your average speed is the harmonic mean: $H = \frac{2}{\frac{1}{40} + \frac{1}{60}} = \frac{2}{\frac{3+2}{120}} = \frac{2 \times 120}{5} = 48$ km/h. This is less than the arithmetic mean of 50 km/h because you spend more time traveling at the slower speed. The harmonic mean correctly accounts for the time spent at each speed, providing a more accurate average for this scenario.

Important Considerations

The harmonic mean requires all positive, non-zero values. Division by zero is undefined, so zeros cannot be included. Negative numbers would make the sum of reciprocals potentially zero or negative, making the result undefined or meaningless. Very small values have a disproportionate effect on the harmonic mean because their reciprocals are very large, so it is important to check for outliers before using the harmonic mean. The tool automatically computes all three Pythagorean means so you can compare them and verify the inequality.

Frequently Asked Questions

What is the harmonic mean?

The harmonic mean is a type of average calculated as the reciprocal of the arithmetic mean of reciprocals. For a dataset of n positive numbers, the formula is H = n / (1/x1 + 1/x2 + ... + 1/xn). It is always less than or equal to the geometric and arithmetic means, and is ideal for averaging rates, ratios, and speeds.

When should I use harmonic mean instead of arithmetic mean?

Use harmonic mean when: (1) averaging rates or ratios like speed or efficiency, (2) equal distances are traveled at different speeds, (3) calculating average price-to-earnings ratios for portfolios, (4) computing F1 scores in machine learning, or (5) finding effective resistance of parallel resistors. Use arithmetic mean for additive quantities like heights, weights, or scores.

Why can't harmonic mean be calculated with zero or negative numbers?

The harmonic mean requires calculating reciprocals (1/x) of each value. Division by zero is undefined, so zeros cannot be included. Negative numbers would make the sum of reciprocals potentially zero or negative, making the result undefined or meaningless. The harmonic mean is designed for positive ratio-scale data only.

How do I calculate average speed using harmonic mean?

When traveling equal distances at different speeds, the average speed is the harmonic mean of the speeds. For example, driving 100 km at 40 km/h and returning 100 km at 60 km/h gives an average speed of H = 2 / (1/40 + 1/60) = 48 km/h, not the arithmetic mean of 50 km/h. This is because you spend more time at the slower speed.

What is the F1 score and how does it use harmonic mean?

The F1 score in machine learning is the harmonic mean of precision and recall: F1 = 2 x (precision x recall) / (precision + recall). Using harmonic mean ensures both metrics must be reasonably high for a good score. Having high precision but low recall (or vice versa) results in a low F1 score, making it a balanced measure of classifier performance.

What is the AM-GM-HM inequality?

For any set of positive numbers, the three Pythagorean means satisfy: Harmonic Mean <= Geometric Mean <= Arithmetic Mean. Equality holds only when all values in the dataset are identical. This relationship is fundamental in mathematics and can be used to check the consistency of your data. The greater the spread between these means, the more varied your data is.