flopscope.numpy.select
fnp.select(condlist, choicelist, default=0)[flopscope source][numpy source]
Return an array drawn from elements in choicelist, depending on conditions.
Adapted from NumPy docs np.select
Return array from list of choices based on conditions. Cost: numel(input).
Parameters
- condlist:list of bool ndarrays
The list of conditions which determine from which array in
choicelistthe output elements are taken. When multiple conditions are satisfied, the first one encountered incondlistis used.- choicelist:list of ndarrays
The list of arrays from which the output elements are taken. It has to be of the same length as
condlist.- default:scalar, optional
The element inserted in
outputwhen all conditions evaluate to False.
Returns
- output:ndarray
The output at position m is the m-th element of the array in
choicelistwhere the m-th element of the corresponding array incondlistis True.
See also
- we.flops.where Return elements from one of two arrays depending on condition.
- we.flops.take
- we.flops.choose
- we.flops.compress
- we.flops.diag
- we.flops.diagonal
Examples
>>> import flopscope.numpy as fnpBeginning with an array of integers from 0 to 5 (inclusive),
elements less than 3 are negated, elements greater than 3
are squared, and elements not meeting either of these conditions
(exactly 3) are replaced with a default value of 42.
>>> x = flops.arange(6)
>>> condlist = [x<3, x>3]
>>> choicelist = [x, x**2]
>>> flops.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]
>>> flops.select(condlist, choicelist, 55)
array([ 0, 1, 2, 3, 4, 25])