bundles / scipy latest / scipy / ndimage / _measurements / mean
function
scipy.ndimage._measurements:mean
Signature
def mean ( input , labels = None , index = None ) Summary
Calculate the mean of the values of an array at labels.
Parameters
input: array_likeArray on which to compute the mean of elements over distinct regions.
labels: array_like, optionalArray of labels of same shape, or broadcastable to the same shape as
input. All elements sharing the same label form one region over which the mean of the elements is computed.index: int or sequence of ints, optionalLabels of the objects over which the mean is to be computed. Default is None, in which case the mean for all values where label is greater than 0 is calculated.
Returns
out: listSequence of same length as
index, with the mean of the different regions labeled by the labels inindex.
Notes
Array API Standard Support
mean has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage import numpy as np a = np.arange(25).reshape((5,5)) labels = np.zeros_like(a) labels[3:5,3:5] = 1 index = np.unique(labels) labels index✓
ndimage.mean(a, labels=labels, index=index)
✗See also
Aliases
-
scipy.ndimage.mean