dpnp.select
- dpnp.select(condlist, choicelist, default=0)[source]
Return an array drawn from elements in choicelist, depending on conditions.
For full documentation refer to
numpy.select
.- Parameters:
condlist (list of bool dpnp.ndarray or usm_ndarray) -- The list of conditions which determine from which array in choicelist the output elements are taken. When multiple conditions are satisfied, the first one encountered in condlist is used.
choicelist (list of dpnp.ndarray or usm_ndarray) -- The list of arrays from which the output elements are taken. It has to be of the same length as condlist.
default ({scalar, dpnp.ndarray, usm_ndarray}, optional) -- The element inserted in output when all conditions evaluate to
False
. Default:0
.
- Returns:
out -- The output at position m is the m-th element of the array in choicelist where the m-th element of the corresponding array in condlist is
True
.- Return type:
dpnp.ndarray
See also
dpnp.where
Return elements from one of two arrays depending on condition.
dpnp.take
Take elements from an array along an axis.
dpnp.choose
Construct an array from an index array and a set of arrays to choose from.
dpnp.compress
Return selected slices of an array along given axis.
dpnp.diag
Extract a diagonal or construct a diagonal array.
dpnp.diagonal
Return specified diagonals.
Examples
>>> import dpnp as np
Beginning with an array of integers from 0 to 5 (inclusive), elements less than
3
are negated, elements greater than3
are squared, and elements not meeting either of these conditions (exactly3
) are replaced with a default value of42
.>>> x = np.arange(6) >>> condlist = [x<3, x>3] >>> choicelist = [x, x**2] >>> np.select(condlist, choicelist, 42) array([ 0, 1, 2, 42, 16, 25])
When multiple conditions are satisfied, the first one encountered in condlist is used.
>>> condlist = [x<=4, x>3] >>> choicelist = [x, x**2] >>> np.select(condlist, choicelist, 55) array([ 0, 1, 2, 3, 4, 25])