I have two arrays x and y like:
x = np.array([6, 3, 5, 2, 1, 4, 9, 7, 8]) y = np.array([2, 1, 3, 5, 3, 9, 8, 10, 7])
I find the index of local minima and maxima as follows:
sortId = np.argsort(x) x = x[sortId] y = y[sortId] minm = np.array([]) maxm = np.array([]) while i < y.size-1: while(y[i+1] >= y[i]): i = i + 1 maxm = np.insert(maxm, 0, i) i++ while(y[i+1] <= y[i]): i = i + 1 minm = np.insert(minm, 0, i) i++
What is the problem in this code? The answer should be the index minima = [2, 5, 7] and maxima = [1, 3, 6] .
prtkp source share