select#
- class brainunit.math.select(condlist, choicelist, default=0, **kwargs)#
Return an array drawn from elements in choicelist, depending on conditions.
- Parameters:
condlist (
list[Array|ndarray|bool|number|bool|int|float|complex]) – 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 (saiunit.Quantity |
Array|ndarray|bool|number|bool|int|float|complex) – The list of arrays from which the output elements are taken. It has to be of the same length as condlist.default (
int) – The element inserted in output when all conditions evaluate to False.
- Returns:
output – 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:
saiunit.Quantity |
Array
Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> conds = [jnp.array([True, False, True]), jnp.array([False, True, False])] >>> choices = [[1, 2, 3] * u.second, [4, 5, 6] * u.second] >>> u.math.select(conds, choices, default=0)