I want to find all the maximums and their index in a numpy array.
I am looking for something simple. I started something like data[1:] < data[:-1] no idea how to get 20 and 30 and their index 2 and 7.
import numpy as np
data = np.array([0,1,20,1,0,1,2,30,2,1,0])
A = data[1:] < data[:-1]
EDIT: Argmax and findpeaks sound difficult (find peaks gives you min and max for instance). I did a np.diff and a loop and I have my index eventhough I try to avoid using loop
import numpy as np
def maximum_index(data):
data = np.diff(data)
index_max = []
for index in range(len(data)-1):
if data[index] > 0 and data[index+1] < 0:
index_max.append(index+1)
return np.asarray(index_max)
data = np.array([0,1,9,1,0,1,2,9,2,1,0])
result_max = maximum_index(data)
Thank you