I wanted to find the max of 2D array along the axis=0 and I don't want to include the value at the row-index. I'm not happy with this solution because I need to run this on a million of rows and I don't want to use for-loop here. I tried numpy.argmax but it calculates the max value of the row including the value at the row index.
My 2D Array
Arry=([[1, 0.5, 0.3, 0, 0.2],
[0, 1, 0.2, 0.8, 0],
[0, 1, 1, 0.3, 0],
[0, 0, 0, 1, 0]])
Expected Output
[1, 3, 1]
The first row [1, 0.5, 0.3, 0, 0.2] has max value at index 1 i.e. 0.5 since value 1 is at row index 0, Similarly in the second row max value is 0.8 i.e. index 3 and the 4th row doesn't have any max value since all are zero
My Code
import numpy as np
for idx,subarry in enumerate(Arry):
newlist=np.delete(subarry, idx)
idx_min=min(np.where(subarry==np.max(newlist))[0])
if idx_min != 0: min_elem_idx.append(idx_min)
print(min_elem_idx)
[1, 3, 1]
I am looking for a Pythonic way to achieve this without using the for loop