I have an original 2-D array
in_arr = np.array([[20,0,10,40,30], [50,40,60,90,80]])
# original array
# [[20, 0, 10, 40, 30],
# [50, 40, 60, 90, 80]]
I need to sort the array by descending and by row, therefore, I use np.argsort(axis=1)
, and the output sorted indices I get are
out_arr1 = np.argsort(in_arr, axis = 1)[:,::-1]
>>> array([[3, 4, 0, 2, 1],
[3, 4, 2, 0, 1]])
Then, I need to extract the first 3 largest number from each array row, the sample desired output being as follows:
# first 3 largest number from each row
# [[40,30,20],
# [90,80,60]]
I have been struggling for a few hours to try to come out correct solution, but still have no idea what I should do. Your valuable time and advice will be much appreciated. Thank you!