bundles / scipy 1.17.1 / scipy / ndimage / _measurements / maximum_position
function
scipy.ndimage._measurements:maximum_position
Signature
def maximum_position ( input , labels = None , index = None ) Summary
Find the positions of the maximums of the values of an array at labels.
Extended Summary
For each region specified by labels, the position of the maximum value of input within the region is returned.
Parameters
input: array_likeArray_like of values.
labels: array_like, optionalAn array of integers marking different regions over which the position of the maximum value of
inputis to be computed.labelsmust have the same shape asinput. Iflabelsis not specified, the location of the first maximum over the whole array is returned.The
labelsargument only works whenindexis specified.index: array_like, optionalA list of region labels that are taken into account for finding the location of the maxima. If
indexis None, the first maximum over all elements wherelabelsis non-zero is returned.The
indexargument only works whenlabelsis specified.
Returns
output: list of tuples of intsList of tuples of ints that specify the location of maxima of
inputover the regions determined bylabelsand whose index is inindex.If
indexorlabelsare not specified, a tuple of ints is returned specifying the location of thefirstmaximal value ofinput.
Notes
Array API Standard Support
maximum_position 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.array([[1, 2, 0, 0], [5, 3, 0, 4], [0, 0, 0, 7], [9, 3, 0, 0]])✓
ndimage.maximum_position(a)
✗lbl = np.array([[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]])✓
ndimage.maximum_position(a, lbl, 1)
✗ndimage.maximum_position(a, lbl)
✗ndimage.maximum_position(a, lbl, 2)
✗See also
- extrema
- label
- maximum_position
- mean
- median
- minimum
- standard_deviation
- sum
- variance
Aliases
-
scipy.ndimage.maximum_position