numpy.argpartition(a,kth,axis=-1,kind='introselect',order=None)[source]¶Perform an indirect partition along the given axis using thealgorithm specified by thekind keyword. It returns an array ofindices of the same shape asa that index data along the givenaxis in partitioned order.
New in version 1.8.0.
| Parameters: | a : array_like
kth : int or sequence of ints
axis : int or None, optional
kind : {‘introselect’}, optional
order : str or list of str, optional
|
|---|---|
| Returns: | index_array : ndarray, int
|
See also
partitionndarray.partitionargsortNotes
Seepartition for notes on the different selection algorithms.
Examples
One dimensional array:
>>>x=np.array([3,4,2,1])>>>x[np.argpartition(x,3)]array([2, 1, 3, 4])>>>x[np.argpartition(x,(1,3))]array([1, 2, 3, 4])
>>>x=[3,4,2,1]>>>np.array(x)[np.argpartition(x,3)]array([2, 1, 3, 4])