bundles / scipy latest / scipy / ndimage / _measurements / variance
function
scipy.ndimage._measurements:variance
source: build-install/usr/lib/python3.14/site-packages/scipy/ndimage/_measurements.py:813
Signature
def variance(input, labels = None, index = None)Summary
Calculate the variance of the values of an N-D image array, optionally at specified sub-regions.
Parameters
input: array_likeNd-image data to process.
labels: array_like, optionalLabels defining sub-regions in
input. If not None, must be same shape asinput.index: int or sequence of ints, optionallabelsto include in output. If None (default), all values wherelabelsis non-zero are used.
Returns
variance: float or ndarrayValues of variance, for each sub-region if
labelsandindexare specified.
Examples
import numpy as np a = np.array([[1, 2, 0, 0], [5, 3, 0, 4], [0, 0, 0, 7], [9, 3, 0, 0]]) from scipy import ndimage✓
ndimage.variance(a)
✗np.float64(7.609375)Features to process can be specified using `labels` and `index`:
lbl, nlbl = ndimage.label(a)
✓ndimage.variance(a, lbl, index=np.arange(1, nlbl+1))
✗array([2.188, 2.25 , 9. ])If no index is given, all non-zero `labels` are processed:
ndimage.variance(a, lbl)
✗np.float64(6.1875)
See also
Aliases
scipy.ndimage.variance