Skip to content

Commit fc85e73

Browse files
committed
Apply comments per PR review by @antonwolfy
Also fix a typo when `condition` is not an array
1 parent 1f51311 commit fc85e73

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

dpnp/dpnp_iface_indexing.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ def _take_1d_index(x, inds, axis, q, usm_type, out=None):
227227

228228
def compress(condition, a, axis=None, out=None):
229229
"""
230-
Return selected slices of an array along given axis.
230+
A copy of `a` without the slices along `axis` for which `condition` is
231+
``False``.
231232
232233
For full documentation refer to :obj:`numpy.choose`.
233234
@@ -239,9 +240,10 @@ def compress(condition, a, axis=None, out=None):
239240
the output is truncated to the length of `condition`.
240241
a : {dpnp.ndarray, usm_ndarray}
241242
Array to extract from.
242-
axis : {int}, optional
243-
Axis along which to extract slices. If `None`, works over the
243+
axis : {None, int}, optional
244+
Axis along which to extract slices. If ``None``, works over the
244245
flattened array.
246+
Default: ``None``.
245247
out : {None, dpnp.ndarray, usm_ndarray}, optional
246248
If provided, the result will be placed in this array. It should
247249
be of the appropriate shape and dtype.
@@ -254,9 +256,41 @@ def compress(condition, a, axis=None, out=None):
254256
255257
See also
256258
--------
259+
:obj:`dpnp.take` : Take elements from an array along an axis.
260+
:obj:`dpnp.choose` : Construct an array from an index array and a set of
261+
arrays to choose from.
262+
:obj:`dpnp.diag` : Extract a diagonal or construct a diagonal array.
263+
:obj:`dpnp.diagonal` : Return specified diagonals.
264+
:obj:`dpnp.select` : Return an array drawn from elements in `choicelist`,
265+
depending on conditions.
257266
:obj:`dpnp.ndarray.compress` : Equivalent method.
258267
:obj:`dpnp.extract` : Equivalent function when working on 1-D arrays.
268+
269+
Examples
270+
--------
271+
>>> import numpy as np
272+
>>> a = np.array([[1, 2], [3, 4], [5, 6]])
273+
>>> a
274+
array([[1, 2],
275+
[3, 4],
276+
[5, 6]])
277+
>>> np.compress([0, 1], a, axis=0)
278+
array([[3, 4]])
279+
>>> np.compress([False, True, True], a, axis=0)
280+
array([[3, 4],
281+
[5, 6]])
282+
>>> np.compress([False, True], a, axis=1)
283+
array([[2],
284+
[4],
285+
[6]])
286+
287+
Working on the flattened array does not return slices along an axis but
288+
selects elements.
289+
290+
>>> np.compress([False, True], a)
291+
array([2])
259292
"""
293+
260294
dpnp.check_supported_arrays_type(a)
261295
if axis is None:
262296
if a.ndim != 1:
@@ -270,7 +304,7 @@ def compress(condition, a, axis=None, out=None):
270304
condition,
271305
dtype=dpnp.bool,
272306
usm_type=a_ary.usm_type,
273-
sycl_queue=a_ary.q,
307+
sycl_queue=a_ary.sycl_queue,
274308
)
275309
else:
276310
cond_ary = dpnp.get_usm_ndarray(condition)

0 commit comments

Comments
 (0)