Skip to content

Commit 3967a79

Browse files
committed
Update dpnp.ndarray.partition method
1 parent bd67b44 commit 3967a79

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

dpnp/dpnp_array.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,35 +1459,54 @@ def nonzero(self):
14591459

14601460
def partition(self, /, kth, axis=-1, kind="introselect", order=None):
14611461
"""
1462-
Return a partitioned copy of an array.
1462+
Partially sorts the elements in the array in such a way that the value
1463+
of the element in k-th position is in the position it would be in a
1464+
sorted array. In the output array, all elements smaller than the k-th
1465+
element are located to the left of this element and all equal or
1466+
greater are located to its right. The ordering of the elements in the
1467+
two partitions on the either side of the k-th element in the output
1468+
array is undefined.
14631469
1464-
Rearranges the elements in the array in such a way that the value of
1465-
the element in `kth` position is in the position it would be in
1466-
a sorted array.
1470+
Refer to `dpnp.partition` for full documentation.
14671471
1468-
All elements smaller than the `kth` element are moved before this
1469-
element and all equal or greater are moved behind it. The ordering
1470-
of the elements in the two partitions is undefined.
1472+
kth : {int, sequence of ints}
1473+
Element index to partition by. The kth element value will be in its
1474+
final sorted position and all smaller elements will be moved before
1475+
it and all equal or greater elements behind it.
1476+
The order of all elements in the partitions is undefined. If
1477+
provided with a sequence of kth it will partition all elements
1478+
indexed by kth of them into their sorted position at once.
1479+
axis : int, optional
1480+
Axis along which to sort. The default is ``-1``, which means sort
1481+
along the the last axis.
14711482
1472-
Refer to `dpnp.partition` for full documentation.
1483+
Default: ``-1``.
14731484
14741485
See Also
14751486
--------
14761487
:obj:`dpnp.partition` : Return a partitioned copy of an array.
1488+
:obj:`dpnp.argpartition` : Indirect partition.
1489+
:obj:`dpnp.sort` : Full sort.
14771490
14781491
Examples
14791492
--------
14801493
>>> import dpnp as np
14811494
>>> a = np.array([3, 4, 2, 1])
14821495
>>> a.partition(3)
14831496
>>> a
1497+
array([1, 2, 3, 4]) # may vary
1498+
1499+
>>> a.partition((1, 3))
1500+
>>> a
14841501
array([1, 2, 3, 4])
14851502
14861503
"""
14871504

1488-
self._array_obj = dpnp.partition(
1489-
self, kth, axis=axis, kind=kind, order=order
1490-
).get_array()
1505+
if axis is None:
1506+
raise TypeError(
1507+
"'NoneType' object cannot be interpreted as an integer"
1508+
)
1509+
self[...] = dpnp.partition(self, kth, axis=axis, kind=kind, order=order)
14911510

14921511
def prod(
14931512
self,

0 commit comments

Comments
 (0)