dpnp.compress
- dpnp.compress(condition, a, axis=None, out=None)[source]
Return selected slices of an array along given axis.
A slice of a is returned for each index along axis where condition is
True.For full documentation refer to
numpy.choose.- Parameters:
condition ({array_like, dpnp.ndarray, usm_ndarray}) -- Array that selects which entries to extract. If the length of condition is less than the size of a along axis, then the output is truncated to the length of condition.
a ({dpnp.ndarray, usm_ndarray}) -- Array to extract from.
axis ({None, int}, optional) --
Axis along which to extract slices. If
None, works over the flattened array.Default:
None.out ({None, dpnp.ndarray, usm_ndarray}, optional) --
If provided, the result will be placed in this array. It should be of the appropriate shape and dtype.
Default:
None.
- Returns:
out -- A copy of the slices of a where condition is
True.- Return type:
dpnp.ndarray
See also
dpnp.takeTake elements from an array along an axis.
dpnp.chooseConstruct an array from an index array and a set of arrays to choose from.
dpnp.diagExtract a diagonal or construct a diagonal array.
dpnp.diagonalReturn specified diagonals.
dpnp.selectReturn an array drawn from elements in choicelist, depending on conditions.
dpnp.ndarray.compressEquivalent method.
dpnp.extractEquivalent function when working on 1-D arrays.
Examples
>>> import numpy as np >>> a = np.array([[1, 2], [3, 4], [5, 6]]) >>> a array([[1, 2], [3, 4], [5, 6]]) >>> np.compress([0, 1], a, axis=0) array([[3, 4]]) >>> np.compress([False, True, True], a, axis=0) array([[3, 4], [5, 6]]) >>> np.compress([False, True], a, axis=1) array([[2], [4], [6]])
Working on the flattened array does not return slices along an axis but selects elements.
>>> np.compress([False, True], a) array([2])