I refactored a code that finds the indices of local minima of the negative part of an array.
The original code identified as minima also the first element of a flat, but the new code doesn’t and I couldn’t find a way.
This is a MWE:
import numpy as np
from scipy import signal
test = np.array([0, 1, 2, 3, 1, 0, -1, -1, -2, -3, -2, 0])
wanted_mins = np.where(((test[:-2] > test[1:-1]) * (test[2:] >= test[1:-1])) & (test[1:-1] < 0))[0] + 1
refactored_mins = signal.find_peaks(np.negative(np.where(test<0, test, 0.0)))[0]
The wanted_mins
are 6
and 9
, but the refactored_mins
is just 9
.
How can I obtain also the first element of plateau points?