Calculate the minimums and maximums of the values of an array at labels, along with their positions.
Parameters : | input : ndarray
labels : ndarray, or None, optional
index : None, int, or sequence of int, optional
|
---|---|
Returns : | minimums, maximums : int or ndarray
min_positions, max_positions : tuple or list of tuples
|
See also
maximum, minimum, maximum_position, minimum_position, center_of_mass
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.extrema(a)
(0, 9, (0, 2), (3, 0))
Features to process can be specified using labels and index:
>>> lbl, nlbl = ndimage.label(a)
>>> ndimage.extrema(a, lbl, index=np.arange(1, nlbl+1))
(array([1, 4, 3]),
array([5, 7, 9]),
[(0.0, 0.0), (1.0, 3.0), (3.0, 1.0)],
[(1.0, 0.0), (2.0, 3.0), (3.0, 0.0)])
If no index is given, non-zero labels are processed:
>>> ndimage.extrema(a, lbl)
(1, 9, (0, 0), (3, 0))