numpy.org
Open in
urlscan Pro
2a06:98c1:3121::c
Public Scan
Submitted URL: https://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html
Effective URL: https://numpy.org/doc/stable/reference/generated/numpy.mean.html
Submission: On December 29 via manual from GB — Scanned from GB
Effective URL: https://numpy.org/doc/stable/reference/generated/numpy.mean.html
Submission: On December 29 via manual from GB — Scanned from GB
Form analysis
1 forms found in the DOMGET ../../search.html
<form class="bd-search d-flex align-items-center" action="../../search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off">
</form>
Text Content
* User Guide * API reference * Development * Release notes * Learn 1.24 dev1.24 (stable)1.231.221.211.201.191.181.171.161.151.141.13 * GitHub * Twitter * Array objects * Array API Standard Compatibility * Constants * Universal functions ( ufunc ) * Routines * Array creation routines * Array manipulation routines * Binary operations * String operations * C-Types Foreign Function Interface ( numpy.ctypeslib ) * Datetime Support Functions * Data type routines * Optionally SciPy-accelerated routines ( numpy.dual ) * Mathematical functions with automatic domain * Floating point error handling * Discrete Fourier Transform ( numpy.fft ) * Functional programming * NumPy-specific help functions * Input and output * Linear algebra ( numpy.linalg ) * Logic functions * Masked array operations * Mathematical functions * Matrix library ( numpy.matlib ) * Miscellaneous routines * Padding Arrays * Polynomials * Random sampling ( numpy.random ) * Set routines * Sorting, searching, and counting * Statistics * numpy.ptp * numpy.percentile * numpy.nanpercentile * numpy.quantile * numpy.nanquantile * numpy.median * numpy.average * numpy.mean * numpy.std * numpy.var * numpy.nanmedian * numpy.nanmean * numpy.nanstd * numpy.nanvar * numpy.corrcoef * numpy.correlate * numpy.cov * numpy.histogram * numpy.histogram2d * numpy.histogramdd * numpy.bincount * numpy.histogram_bin_edges * numpy.digitize * Test Support ( numpy.testing ) * Window functions * Typing ( numpy.typing ) * Global State * Packaging ( numpy.distutils ) * NumPy Distutils - Users Guide * Status of numpy.distutils and migration advice * NumPy C-API * CPU/SIMD Optimizations * NumPy security * NumPy and SWIG On this page * mean NUMPY.MEAN# numpy.mean(a, axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)[source]# Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs. Parameters: aarray_like Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted. axisNone or int or tuple of ints, optional Axis or axes along which the means are computed. The default is to compute the mean of the flattened array. New in version 1.7.0. If this is a tuple of ints, a mean is performed over multiple axes, instead of a single axis or all the axes as before. dtypedata-type, optional Type to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype. outndarray, optional Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details. keepdimsbool, optional 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. If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised. wherearray_like of bool, optional Elements to include in the mean. See reduce for details. New in version 1.20.0. Returns: mndarray, see dtype parameter above If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned. See also average Weighted average std, var, nanmean, nanstd, nanvar Notes The arithmetic mean is the sum of the elements along the axis divided by the number of elements. Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. Examples >>> a = np.array([[1, 2], [3, 4]]) >>> np.mean(a) 2.5 >>> np.mean(a, axis=0) array([2., 3.]) >>> np.mean(a, axis=1) array([1.5, 3.5]) In single precision, mean can be inaccurate: >>> a = np.zeros((2, 512*512), dtype=np.float32) >>> a[0, :] = 1.0 >>> a[1, :] = 0.1 >>> np.mean(a) 0.54999924 Computing the mean in float64 is more accurate: >>> np.mean(a, dtype=np.float64) 0.55000000074505806 # may vary Specifying a where argument: >>> a = np.array([[5, 9, 13], [14, 10, 12], [11, 15, 19]]) >>> np.mean(a) 12.0 >>> np.mean(a, where=[[True], [False], [False]]) 9.0 previous numpy.average next numpy.std © Copyright 2008-2022, NumPy Developers. Created using Sphinx 5.3.0.