I'm currently working in removing some 1D arrays based on the values of one of the columns from a 2D array. The first column may have different and repeated values, I want to keep one of each repeated value based on the max value of the second column (this is just an example, the 2d array may be bigger) here is what I tried
import numpy as np
arr = np.array([[ 36.06, 209.14],
[ 36.06, 214.55],
[ 36.06, 215.91],
[ 36.06, 225.29],
[ 41.11, 186.76],
[ 41.11, 191.79],
[ 41.11, 197.21],
[ 41.11, 197.33],
[ 41.11, 201.19],
[ 41.11, 206.15],
[ 50.25, 165.51],
[ 50.25, 174.32],
[ 59.03, 148.79]])
biggest = 0
aux = []
for i in range(arr.shape[0]-1):
j = i+1
if (arr[i][0] == arr[j][0]):
if (arr[i][1] < arr[j][1] and arr[j][1] > biggest):
biggest = j
if (arr[i][0] != arr[j][0]):
aux.append(arr[biggest])
print(np.array(aux))
#Output = [[ 36.06 225.29]
# [ 41.11 206.15]
# [ 50.25 174.32]]
As you can see, I get almost the desired result, my expected result should be something like this...
Output = [[ 36.06 225.29]
[ 41.11 206.15]
[ 50.25 174.32]
[ 59.03 148.79]]
The thing is I'm missing the last array and maybe there is an easier way using numpy built-in functions that I'm missing. Thank you in advance!