HarmonicMean[data]
gives the harmonic mean of the values in data.
HarmonicMean
HarmonicMean[data]
gives the harmonic mean of the values in data.
Details
- For VectorQ data
, the harmonic mean is given by
. - For MatrixQ data, HarmonicMean[{{x1,y1},{x2,y2},…}] is equivalent to {HarmonicMean[{x1,x2,…}],HarmonicMean[{y1,y2,…}]}. »
- HarmonicMean handles both numerical and symbolic data.
- The data can have the following additional forms and interpretations:
-
SparseArray as an array, equivalent to Normal[data] » QuantityArray quantities as an array » WeightedData weighted mean, based on the underlying EmpiricalDistribution » EventData based on the underlying SurvivalDistribution » TimeSeries, TemporalData, … vector or array of values (the time stamps ignored) » Image,Image3D RGB channel's values or grayscale intensity value » Audio amplitude values of all channels »
Examples
open all close allBasic Examples (2)
Scope (12)
Basic Uses (6)
Exact input yields exact output:
HarmonicMean[{1, 2, 3, 4}]HarmonicMean[{π, E, 2}]Approximate input yields approximate output:
HarmonicMean[{1., 2., 3., 4.}]HarmonicMean[N[{1, 2, 3, 4}, 30]]Find the harmonic mean of WeightedData:
data = {8, 3, 5, 4, 9, 1, 4, 2, 2, 3};
weights = {0.15, 0.09, 0.12, 0.10, 0.16, 0.3, 0.11, 0.08, 0.08, 0.09};HarmonicMean[WeightedData[data, weights]]Find the harmonic mean of EventData:
e = {1.0, 2.1, 3.2, 4.5, 5.7};
ci = {0, 0, 0, 1, 0};HarmonicMean[EventData[e, ci]]Find the harmonic mean of a TimeSeries:
v = {3, 8, 4, 11, 9, 2};
t = {1, 3, 5, 7, 8, 10};
ts = TimeSeries[v, {t}];HarmonicMean[ts]//NThe harmonic mean depends only on the values:
HarmonicMean[ts["Values"]]//NCompute a weighted harmonic mean:
HarmonicMean[WeightedData[ts]]//NFind the harmonic mean of data involving quantities:
data = Quantity[RandomReal[1, 6], "Meters"]HarmonicMean[data]Array Data (4)
HarmonicMean for a 2D matrix gives columnwise means:
HarmonicMean[Array[Subscript[a, ##]&, {2, 2}]]HarmonicMean[RandomReal[1, 10 ^ 7]]HarmonicMean[RandomReal[1, {10 ^ 6, 3}]]SparseArray data can be used just like dense arrays:
HarmonicMean[SparseArray[{{1} -> a, {2} -> b, {3} -> 7}, {3}, 1]]HarmonicMean[SparseArray[{{1, 1} -> 3, {2, 1} -> 4, {2, 2} -> 7}, {2, 2}, 1]]sp = SparseArray[{{i_, i_} :> i, {i_, j_} /; j == i + 1 :> j}, {100, 10}, 1]HarmonicMean[sp]Find the harmonic mean of a QuantityArray:
data = QuantityArray[RandomReal[1, 6], "Pounds"]HarmonicMean[data]Image and Audio Data (2)
Channelwise harmonic mean value of an RGB image:
HarmonicMean[[image]]RGBColor[%]Harmonic mean intensity value of a grayscale image:
HarmonicMean[[image]]On audio objects, HarmonicMean works channelwise:
a = Audio[Array[2 + Sin[2π 1200 #]&, 44100, {0, 1}]]AudioMeasurements[a, "Channels"]HarmonicMean[a]Applications (1)
Find the harmonic mean for the heights of children in a class:
heights = Quantity[{134, 143, 131, 140, 145, 136, 131, 136, 143, 136, 133, 145, 147,
150, 150, 146, 137, 143, 132, 142, 145, 136, 144, 135, 141}, "Centimeters"];ListPlot[heights, Filling -> Axis, AxesLabel -> Automatic](hm = HarmonicMean[heights])//NListPlot[{heights, {{0, hm}, {25, hm}}}, Joined -> {False, True}, Filling -> Axis, AxesLabel -> Automatic]Properties & Relations (6)
HarmonicMean is the inverse of Mean of the inverse of the data:
data = RandomReal[10, 10];1 / Mean[1 / data]HarmonicMean[data]HarmonicMean is very sensible to values close to zero:
data = RandomReal[10, 10];data[[1]] = 0.HarmonicMean[data]This agrees with the definition:
1 / Mean[1 / data]HarmonicMean is logarithmically related to GeometricMean for positive values:
1 / Log[GeometricMean[{a, b, c, d}]]//PowerExpandHarmonicMean[1 / Log[{a, b, c, d}]]For positive data
, HarmonicMean[d]≤GeometricMean[d]≤Mean[d]:
data = RandomReal[1, 100];HarmonicMean[data] ≤ GeometricMean[data] ≤ Mean[data]Prove the inequality symbolically:
data = {a, b, c};FullSimplify[HarmonicMean[data] ≤ GeometricMean[data] ≤ Mean[data], Min[data] ≥ 0]HarmonicMean[Range[n]] is inversely related to HarmonicNumber[n]:
With[{n = RandomInteger[{1, 10 ^ 3}]},
HarmonicNumber[n] == n / HarmonicMean[Range[n]]]The harmonic mean of the shifted data is larger than the shifted harmonic mean of the original data (assuming the shift is a positive number):
data = RandomReal[1, 20];HarmonicMean[c + data] > c + HarmonicMean[data]//FullSimplify[#, c > 0]&Possible Issues (1)
HarmonicMean will return 0 when the audio channels have a 0 in them; this is common for real-world audio samples:
a = ExampleData[{"Audio", "Drums"}]HarmonicMean[a]Min[Abs@a]Mean will clip channel values to values that can be represented with machine numbers:
1 / Mean[1 / a]Tech Notes
Related Guides
Text
Wolfram Research (2007), HarmonicMean, Wolfram Language function, https://reference.wolfram.com/language/ref/HarmonicMean.html (updated 2023).
CMS
Wolfram Language. 2007. "HarmonicMean." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/HarmonicMean.html.
APA
Wolfram Language. (2007). HarmonicMean. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HarmonicMean.html
BibTeX
@misc{reference.wolfram_2026_harmonicmean, author="Wolfram Research", title="{HarmonicMean}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/HarmonicMean.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_harmonicmean, organization={Wolfram Research}, title={HarmonicMean}, year={2023}, url={https://reference.wolfram.com/language/ref/HarmonicMean.html}, note=[Accessed: 13-June-2026]}