dpnp.ndarray.partition

method

ndarray.partition(kth, axis=-1, kind='introselect', order=None)

Partially sorts the elements in the array in such a way that the value of the element in k-th position is in the position it would be in a sorted array. In the output array, all elements smaller than the k-th element are located to the left of this element and all equal or greater are located to its right. The ordering of the elements in the two partitions on the either side of the k-th element in the output array is undefined.

Refer to dpnp.partition for full documentation.

kth{int, sequence of ints}

Element index to partition by. The kth element value will be in its final sorted position and all smaller elements will be moved before it and all equal or greater elements behind it. The order of all elements in the partitions is undefined. If provided with a sequence of kth it will partition all elements indexed by kth of them into their sorted position at once.

axisint, optional

Axis along which to sort. The default is -1, which means sort along the the last axis.

Default: -1.

See also

dpnp.partition

Return a partitioned copy of an array.

dpnp.argpartition

Indirect partition.

dpnp.sort

Full sort.

Examples

>>> import dpnp as np
>>> a = np.array([3, 4, 2, 1])
>>> a.partition(3)
>>> a
array([1, 2, 3, 4]) # may vary
>>> a.partition((1, 3))
>>> a
array([1, 2, 3, 4])