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.extract
is equivalent toa[condition]
.Note that
dpnp.place
does the exact opposite ofdpnp.extract
.For full documentation refer to
numpy.extract
.- Parameters:
condition ({array_like, scalar}) -- An array whose non-zero or
True
entries 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.take
Take elements from an array along an axis.
dpnp.put
Replaces specified elements of an array with given values.
dpnp.copyto
Copies values from one array to another, broadcasting as necessary.
dpnp.compress
Return selected slices of an array along given axis.
dpnp.place
Change 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])