Statistics: harmmean

### Function Reference: `harmmean`

statistics: m = harmmean (x)
statistics: m = harmmean (x, "all")
statistics: m = harmmean (x, dim)
statistics: m = harmmean (x, vecdim)
statistics: m = harmmean (…, nanflag)

Compute the harmonic mean of x.

- If x is a vector, then `harmmean(x)` returns the harmonic mean of the elements in x defined as $$ {\rm harmmean}(x) = \frac{N}{\sum_{i=1}^N \frac{1}{x_i}} $$ where N is the length of the x vector.
- If x is a matrix, then `harmmean(x)` returns a row vector with the harmonic mean of each columns in x.
- If x is a multidimensional array, then `harmmean(x)` operates along the first nonsingleton dimension of x.
- x must not contain any negative or complex values.

`harmmean(x, "all")` returns the harmonic mean of all the elements in x. If x contains any 0, then the returned value is 0.

`harmmean(x, dim)` returns the harmonic mean along the operating dimension dim of x. Calculating the harmonic mean of any subarray containing any 0 will return 0.

`harmmean(x, vecdim)` returns the harmonic mean over the dimensions specified in the vector vecdim. For example, if x is a 2-by-3-by-4 array, then `harmmean(x, [1 2])` returns a 1-by-1-by-4 array. Each element of the output array is the harmonic mean of the elements on the corresponding page of x. If vecdim indexes all dimensions of x, then it is equivalent to `harmmean (x, "all")`. Any dimension in vecdim greater than `ndims (x)` is ignored.

`harmmean(…, nanflag)` specifies whether to exclude NaN values from the calculation, using any of the input argument combinations in previous syntaxes. By default, harmmean includes NaN values in the calculation (nanflag has the value "includenan"). To exclude NaN values, set the value of nanflag to "omitnan".

See also: geomean, mean

Source Code: harmmean