dpnp.extract
- dpnp.extract(condition, a)[source]
Return the elements of an array that satisfy some condition.
This is equivalent to
dpnp.compress(dpnp.ravel(condition), dpnp.ravel(a)). If condition is booleandpnp.extractis equivalent toa[condition].Note that
dpnp.placedoes the exact opposite ofdpnp.extract.For full documentation refer to
numpy.extract.- Parameters:
condition ({array_like, scalar}) -- An array whose non-zero or
Trueentries indicate the element of a to extract.a ({dpnp.ndarray, usm_ndarray}) -- Input array of the same size as condition.
- Returns:
out -- Rank 1 array of values from a where condition is
True.- Return type:
dpnp.ndarray
See also
dpnp.takeTake elements from an array along an axis.
dpnp.putReplaces specified elements of an array with given values.
dpnp.copytoCopies values from one array to another, broadcasting as necessary.
dpnp.compressReturn selected slices of an array along given axis.
dpnp.placeChange elements of an array based on conditional and input values.
Examples
>>> import dpnp as np >>> a = np.arange(12).reshape((3, 4)) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> condition = np.mod(a, 3) == 0 >>> condition array([[ True, False, False, True], [False, False, True, False], [False, True, False, False]]) >>> np.extract(condition, a) array([0, 3, 6, 9])
If condition is boolean:
>>> a[condition] array([0, 3, 6, 9])