Loading [MathJax]/jax/input/TeX/config.js
scipy 1.10.1 Pypi GitHub Homepage
Other Docs

NotesParametersReturnsBackRef
hmean(a, axis=0, dtype=None, *, weights=None, nan_policy='propagate', keepdims=False)

The weighted harmonic mean of the array a_i associated to weights w_i is:

\frac{ \sum_{i=1}^n w_i }{ \sum_{i=1}^n \frac{w_i}{a_i} } \, ,

and, with equal weights, it gives:

\frac{ n }{ \sum_{i=1}^n \frac{1}{a_i} } \, .

Notes

The harmonic mean is computed over a single dimension of the input array, axis=0 by default, or all values in the array if axis=None. float64 intermediate and return values are used for integer inputs.

Beginning in SciPy 1.9, np.matrix inputs (not recommended for new code) are converted to np.ndarray before the calculation is performed. In this case, the output will be a scalar or np.ndarray of appropriate shape rather than a 2D np.matrix. Similarly, while masked elements of masked arrays are ignored, the output will be a scalar or np.ndarray rather than a masked array with mask=False.

Parameters

a : array_like

Input array, masked array or object that can be converted to an array.

axis : int or None, default: 0

If an int, the axis of the input along which to compute the statistic. The statistic of each axis-slice (e.g. row) of the input will appear in a corresponding element of the output. If None, the input will be raveled before computing the statistic.

dtype : dtype, optional

Type of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.

weights : array_like, optional

The weights array can either be 1-D (in which case its length must be the size of a along the given axis) or of the same shape as a. Default is None, which gives each value a weight of 1.0.

nan_policy : {'propagate', 'omit', 'raise'}

Defines how to handle input NaNs.

  • propagate: if a NaN is present in the axis slice (e.g. row) along which the statistic is computed, the corresponding entry of the output will be NaN.
  • omit: NaNs will be omitted when performing the calculation. If insufficient data remains in the axis slice along which the statistic is computed, the corresponding entry of the output will be NaN.
  • raise: if a NaN is present, a ValueError will be raised.
keepdims : bool, default: False

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Returns

hmean : ndarray

See dtype parameter above.

Calculate the weighted harmonic mean along the specified axis.

See Also

gmean

Geometric mean

numpy.average

Weighted average

numpy.mean

Arithmetic average

Examples

from scipy.stats import hmean
hmean([1, 4])
hmean([1, 2, 3, 4, 5, 6, 7])
hmean([1, 4, 7], weights=[3, 1, 3])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.stats._stats_py:pmean scipy.stats._stats_py:gmean

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

numpy.averageaveragescipy.stats._stats_py:gmean_stats_py:gmeanscipy.stats._stats_py:pmean_stats_py:pmeannumpy.meanmean

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/stats/_stats_py.py#272
type: <class 'function'>
Commit: