where¶
- where(condition: array, x1: array | int | float | complex | bool, x2: array | int | float | complex | bool, /) array ¶
Returns elements chosen from
x1
orx2
depending oncondition
.- Parameters:
condition (array) – when
True
, yieldx1_i
; otherwise, yieldx2_i
. Should have a boolean data type. Must be compatible withx1
andx2
(see Broadcasting).x1 (Union[array, int, float, complex, bool]) – first input array. Must be compatible with
condition
andx2
(see Broadcasting).x2 (Union[array, int, float, complex, bool]) – second input array. Must be compatible with
condition
andx1
(see Broadcasting).
- Returns:
out (array) – an array with elements from
x1
wherecondition
isTrue
, and elements fromx2
elsewhere. The returned array must have a data type determined by Type Promotion Rules rules with the arraysx1
andx2
.
Notes
At least one of
x1
andx2
must be an array.If either
x1
orx2
is a scalar value, the returned array must have a data type determined according to Mixing arrays with Python scalars.
Changed in version 2024.12: Added support for scalar arguments.