Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.
librosa.util.localmax
- librosa.util.localmax(x, axis=0)[source]
Find local maxima in an array
An element
x[i]
is considered a local maximum if the following conditions are met:x[i] > x[i-1]
x[i] >= x[i+1]
Note that the first condition is strict, and that the first element
x[0]
will never be considered as a local maximum.- Parameters:
- xnp.ndarray [shape=(d1,d2,…)]
input vector or array
- axisint
axis along which to compute local maximality
- Returns:
- mnp.ndarray [shape=x.shape, dtype=bool]
indicator array of local maximality along
axis
See also
Examples
>>> x = np.array([1, 0, 1, 2, -1, 0, -2, 1]) >>> librosa.util.localmax(x) array([False, False, False, True, False, True, False, True], dtype=bool)
>>> # Two-dimensional example >>> x = np.array([[1,0,1], [2, -1, 0], [2, 1, 3]]) >>> librosa.util.localmax(x, axis=0) array([[False, False, False], [ True, False, False], [False, True, True]], dtype=bool) >>> librosa.util.localmax(x, axis=1) array([[False, False, True], [False, False, True], [False, False, True]], dtype=bool)