This is a bit confusing, but you can get what you need with np.argpartition . Take a simple array and shuffle it:
>>> a = np.arange(10) >>> np.random.shuffle(a) >>> a array([5, 6, 4, 9, 2, 1, 3, 0, 7, 8])
If you want to find, for example, a quantile index of 0.25, this will correspond to the element at the idx position of the sorted array:
>>> idx = 0.25 * (len(a) - 1) >>> idx 2.25
You need to figure out how to round this to int, let's say you go with the nearest integer:
>>> idx = int(idx + 0.5) >>> idx 2
If you call np.argpartition now, this is what you get:
>>> np.argpartition(a, idx) array([7, 5, 4, 3, 2, 1, 6, 0, 8, 9], dtype=int64) >>> np.argpartition(a, idx)[idx] 4 >>> a[np.argpartition(a, idx)[idx]] 2
It is easy to verify that these last two expressions are, respectively, the index and value of the quantum .25.