bundles / numpy latest / numpy / select
_ArrayFunctionDispatcher
numpy:select
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py :812
Signature
def select ( condlist , choicelist , default = 0 ) Summary
Return an array drawn from elements in choicelist, depending on conditions.
Parameters
condlist: list of bool ndarraysThe 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 ndarraysThe list of arrays from which the output elements are taken. It has to be of the same length as
condlist.default: scalar, optionalThe element inserted in output when all conditions evaluate to False.
Returns
output: ndarrayThe output at position m is the m-th element of the array in
choicelistwhere the m-th element of the corresponding array incondlistis True.
Examples
import numpy as np
✓x = np.arange(6) condlist = [x<3, x>3] choicelist = [-x, x**2]✓
np.select(condlist, choicelist, 42)
✗condlist = [x<=4, x>3] choicelist = [x, x**2] np.select(condlist, choicelist, 55)✓
See also
- choose
- compress
- diag
- diagonal
- take
- where
Return elements from one of two arrays depending on condition.
Aliases
-
numpy.select