numpy.argpartition(a, kth, axis=-1, kind='introselect', order=None)
[source]
Perform an indirect partition along the given axis using the algorithm specified by the kind
keyword. It returns an array of indices of the same shape as a
that index data along the given axis in partitioned order.
New in version 1.8.0.
Parameters: |
a : array_like Array to sort. kth : int or sequence of ints Element index to partition by. The k-th element will be in its final sorted position and all smaller elements will be moved before it and all larger elements behind it. The order all elements in the partitions is undefined. If provided with a sequence of k-th it will partition all of them into their sorted position at once. axis : int or None, optional Axis along which to sort. The default is -1 (the last axis). If None, the flattened array is used. kind : {‘introselect’}, optional Selection algorithm. Default is ‘introselect’ order : str or list of str, optional When |
---|---|
Returns: |
index_array : ndarray, int Array of indices that partition |
See also
partition
ndarray.partition
argsort
See partition
for notes on the different selection algorithms.
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])
© 2008–2017 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.argpartition.html