numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
argpartition(a, kth, axis=-1, kind='introselect', order=None)
versionadded

Notes

See partition for notes on the different selection algorithms.

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.

deprecated

Passing booleans as index is deprecated.

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 a is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.

Returns

index_array : ndarray, int

Array of indices that partition a along the specified axis. If a is one-dimensional, a[index_array] yields a partitioned a. More generally, np.take_along_axis(a, index_array, axis=a) always yields the partitioned a, irrespective of dimensionality.

Perform an indirect partition along the given axis using the algorithm specified by the :None:None:`kind` keyword. It returns an array of indices of the same shape as a that index data along the given axis in partitioned order.

See Also

argsort

Full indirect sort.

ndarray.partition

Inplace partition.

partition

Describes partition algorithms used.

take_along_axis

Apply index_array from argpartition to an array as if by calling partition.

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])

Multi-dimensional array:

>>> x = np.array([[3, 4, 2], [1, 3, 1]])
... index_array = np.argpartition(x, kth=1, axis=-1)
... np.take_along_axis(x, index_array, axis=-1) # same as np.partition(x, kth=1) array([[2, 3, 4], [1, 1, 3]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.take_along_axis numpy.partition numpy.put_along_axis numpy.argsort

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/fromnumeric.py#766
type: <class 'function'>
Commit: