argrelextrema#
- scipy.signal.argrelextrema(data, comparator, axis=0, order=1, mode='clip')[source]#
Calculate the relative extrema of data.
- Parameters:
- datandarray
Array in which to find the relative extrema.
- comparatorcallable
Function to use to compare two data points. Should take two arrays as arguments.
- axisint, optional
Axis over which to select from data. Default is 0.
- orderint, optional
How many points on each side to use for the comparison to consider
comparator(n, n+x)to be True.- modestr, optional
How the edges of the vector are treated. ‘wrap’ (wrap around) or ‘clip’ (treat overflow as the same as the last (or first) element). Default is ‘clip’. See
numpy.take.
- Returns:
- extrematuple of ndarrays
Indices of the maxima in arrays of integers.
extrema[k]is the array of indices of axis k of data. Note that the return value is a tuple even when data is 1-D.
Notes
Added in version 0.11.0.
Array API Standard Support
argrelextremahas experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1and 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
⛔
⛔
Dask
⛔
n/a
See Support for the array API standard for more information.
Examples
>>> import numpy as np >>> from scipy.signal import argrelextrema >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) >>> argrelextrema(x, np.greater) (array([3, 6]),) >>> y = np.array([[1, 2, 1, 2], ... [2, 2, 0, 0], ... [5, 3, 4, 4]]) ... >>> argrelextrema(y, np.less, axis=1) (array([0, 2]), array([2, 1]))