Find the index of the k smallest values of a numpy array

后端 未结 4 788
南旧
南旧 2020-12-07 14:44

In order to find the index of the smallest value, I can use argmin:

import numpy as np
A = np.array([1, 7, 9, 2, 0.1, 17, 17, 1.5])
print A.arg         


        
4条回答
  •  旧时难觅i
    2020-12-07 15:23

    numpy.partition(your_array, k) is an alternative. No slicing necessary as it gives the values sorted until the kth element.

提交回复
热议问题