# where¶

paddle. where ( condition, x, y, name=None ) [source]

Return a tensor of elements selected from either $x$ or $y$, depending on $condition$.

$\begin{split}out_i = \\begin{cases} x_i, \quad \\text{if} \\ condition_i \\ is \\ True \\\\ y_i, \quad \\text{if} \\ condition_i \\ is \\ False \\\\ \\end{cases}\end{split}$
Parameters
• condition (Tensor) – The condition to choose x or y.

• x (Tensor) – x is a Tensor with data type float32, float64, int32, int64.

• y (Tensor) – y is a Tensor with data type float32, float64, int32, int64.

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A Tensor with the same data dype as x.

Return type

Tensor

Examples

import paddle

x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2])
y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0])
out = paddle.where(x>1, x, y)

print(out)
#out: [1.0, 1.0, 3.2, 1.2]