librosa.util.localmax

librosa.util.localmax(x, axis=0)[source]

Find local maxima in an array x.

Parameters:
x : np.ndarray [shape=(d1,d2,…)]

input vector or array

axis : int

axis along which to compute local maximality

Returns:
m : np.ndarray [shape=x.shape, dtype=bool]

indicator array of local maximality along axis

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)