Nov-13-2017, 05:29 PM
(This post was last modified: Nov-13-2017, 05:29 PM by PythonNewbie.)
I think it has to do with what argsort() returns. For example,
How to use argsort() or any other method to obtain the same results as argmin() when k = 1?
import numpy as np k = 1 x = np.array([0, 1, -1, 4, 2]) y = np.array(['a', 'b', 'c', 'd', 'e']) indx_argmin = x.argmin() indx_argsort = x.argsort()[:k] print(indx_argmin, y[indx_argmin]) print(indx_argsort, y[indx_argsort])outputs
Output:2 c
[2] ['c']
Apparently they are not the same.How to use argsort() or any other method to obtain the same results as argmin() when k = 1?