I have a 1D numpy array and I need to create a new numpy array with the amax results (better the argmax result) of every 'n' positions of the array.
Let me try an example:
Consider I have a 1D numpy array with values from 1 to 5. I want to have a new numpy array with the amax, or argmax, of each 3 positions in the original numpy array.
original numpy array and range of amax action:
| 1 | 2 | 3 | 4 | 5 |
------| 5 |--
3 |-------|
4 |-------|
5 |-------|
--| 5 |-----
My new numpy array, considering the amax of each 3 positions will be ([5, 3, 4, 5, 5]).
Can anyone think of a way to doing that just using numpy?
I was able to do it using a 'for', but I don't think that is the best option. Here is a snippet of what I did using 'for':
for i in range(array-1):
best = np.argmax([array[i-1], array[i], array[i+1,2]])
best_array[i] = array[i+best-1]