where¶
- where(condition: array, x1: array | int | float | complex | bool, x2: array | int | float | complex | bool, /) array¶
Returns elements chosen from
x1orx2depending oncondition.- Parameters:
condition (array) – when
True, yieldx1_i; otherwise, yieldx2_i. Should have a boolean data type. Must be broadcast-compatible withx1andx2(see Broadcasting).x1 (Union[array, int, float, complex, bool]) – first input array. Must be broadcast-compatible with
conditionandx2(see Broadcasting).x2 (Union[array, int, float, complex, bool]) – second input array. Must be broadcast-compatible with
conditionandx1(see Broadcasting).
- Returns:
out (array) – an array with elements from
x1whereconditionisTrue, and elements fromx2elsewhere. The returned array must have a data type determined by Type Promotion Rules rules with the arraysx1andx2.
Notes
At least one of
x1andx2must be an array.If either
x1orx2is 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 scalar argument support.
Changed in version 2024.12: Clarified that the
conditionargument should have a boolean data type.