bundles / scipy latest / scipy / ndimage / _measurements / maximum
function
scipy.ndimage._measurements:maximum
source: build-install/usr/lib/python3.14/site-packages/scipy/ndimage/_measurements.py:1100
Signature
def maximum(input, labels = None, index = None)Summary
Calculate the maximum of the values of an array over labeled regions.
Parameters
input: array_likeArray_like of values. For each region specified by
labels, the maximal values ofinputover the region is computed.labels: array_like, optionalAn array of integers marking different regions over which the maximum value of
inputis to be computed.labelsmust have the same shape asinput. Iflabelsis not specified, the maximum over the whole array is returned.index: array_like, optionalA list of region labels that are taken into account for computing the maxima. If index is None, the maximum over all elements where
labelsis non-zero is returned.
Returns
output: a scalar or list of integers or floats based on input type.List of maxima of
inputover the regions determined bylabelsand whose index is inindex. Ifindexorlabelsare not specified, a float is returned: the maximal value ofinputiflabelsis None, and the maximal value of elements wherelabelsis greater than zero ifindexis None.
Notes
The function returns a Python list and not a NumPy array, use np.array to convert the list to an array.
Examples
import numpy as np a = np.arange(16).reshape((4,4)) a labels = np.zeros_like(a) labels[:2,:2] = 1 labels[2:, 1:3] = 2 labels from scipy import ndimage✓
ndimage.maximum(a) ndimage.maximum(a, labels=labels, index=[1,2]) ndimage.maximum(a, labels=labels)✗
np.int64(14)
b = np.array([[1, 2, 0, 0], [5, 3, 0, 4], [0, 0, 0, 7], [9, 3, 0, 0]]) labels, labels_nb = ndimage.label(b) labels✓
array([[1, 1, 0, 0],
[1, 1, 0, 2],
[0, 0, 0, 2],
[3, 3, 0, 0]], dtype=int32)
ndimage.maximum(b, labels=labels, index=np.arange(1, labels_nb + 1))
✗array([5, 7, 9])
See also
Aliases
scipy.ndimage.maximum