I got a numpy 2D array, and the list of indices corresponding to the top 3 elements obtained using argsort. Now, I am trying to extract the values corresponding to this indices, and it is not working. What is the workaround ?.
A = array([[0.19334242, 0.9787497 , 0.41453434, 0.35298119, 0.17943745,
0.63468207, 0.43840688],
[0.39811914, 0.68040634, 0.7589702 , 0.3573046 , 0.16365397,
0.86329535, 0.48559053],
[0.5848541 , 0.54203383, 0.27262654, 0.21979374, 0.06917679,
0.10586995, 0.57083441],
[0.76765549, 0.05703751, 0.83383973, 0.71867625, 0.16338699,
0.85721418, 0.5953548 ]])
np.flip(A.argsort(),axis=1)[:,0:3]
array([[1, 5, 6],
[5, 2, 1],
[0, 6, 1],
[5, 2, 0]])
gets error
>>> A[np.flip(A.argsort(),axis=1)[:,0:3]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: index 5 is out of bounds for axis 0 with size 4