Calculate the variance of the values of an n-D image array, optionally at specified sub-regions.
Parameters : | input : array_like
labels : array_like, optional
index : int or sequence of ints, optional
|
---|---|
Returns : | vars : float or ndarray
|
See also
Examples
>>> 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)
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.1875, 2.25 , 9. ])
If no index is given, all non-zero labels are processed:
>>> ndimage.variance(a, lbl)
6.1875