'Find the index of rows which has a special condition in a numpy array

I have a (n,2) array. I want to choose the index of array which their value is equal to the maximum of their rows. For example, in the below array, the maximum of column 0 is 7, and the maximum of column 1 is 10. So, I only want to get the rows which their values are (7,10). Here is an example:

 a = np.array([[1,2], [1,6], [7,10], [7, 10], [0,1], [1,9], [0,5]])

The desired output is:

output = np.array([2,3])

Thank you for your help.

I've tried to used the np.select, however it seems that have an arguments which need condition choice and etx, then it seems that its not effective. Also, I could not get the true value with that.



Solution 1:[1]

In the first step we can find maximum values columnar using np.amax and then find rows where both columns satisfy the condition:

cols_max = np.amax(a, axis=0)
result = np.argwhere((a == cols_max).all(axis=1))  # add ".squeeze()" to reduce dimensions 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ali_Sh