# tensorplay.functional.where Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.where.html ```python tensorplay.functional.where(condition, input, other, *, out=None) → Tensor ``` Return a tensor of elements selected from either input or other, depending on condition. The operation is defined as: $$\begin{split}\text{out}_i = \begin{cases} \text{input}_i & \text{if } \text{condition}_i \\ \text{other}_i & \text{otherwise} \\ \end{cases}\end{split}$$ > **Note** > > The tensors condition, input, other must be broadcastable. Parameters: - condition (BoolTensor) – When True (nonzero), yield input, otherwise yield other - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – value (if input is a scalar) or values selected at indices where condition is True - other ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) or [Scalar](/docs/generated/tensorplay.Scalar.html#tensorplay.Scalar)) – value (if other is a scalar) or values selected at indices where condition is False Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Returns: A tensor of shape equal to the broadcasted shape of condition, input, other Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) Example: ``` >>> x = tensorplay.randn(3, 2) >>> y = tensorplay.ones(3, 2) >>> x tensor([[-0.4620, 0.3139], [ 0.3898, -0.7197], [ 0.0478, -0.1657]]) >>> tensorplay.where(x > 0, 1.0, 0.0) tensor([[0., 1.], [1., 0.], [1., 0.]]) >>> tensorplay.where(x > 0, x, y) tensor([[ 1.0000, 0.3139], [ 0.3898, 1.0000], [ 0.0478, 1.0000]]) >>> x = tensorplay.randn(2, 2, dtype=tensorplay.double) >>> x tensor([[ 1.0779, 0.0383], [-0.8785, -1.1089]], dtype=tensorplay.float64) >>> tensorplay.where(x > 0, x, 0.) tensor([[1.0779, 0.0383], [0.0000, 0.0000]], dtype=tensorplay.float64) ``` ```python tensorplay.functional.where(condition) → tuple of LongTensor ``` tensorplay.where(condition) is identical to tensorplay.nonzero(condition, as_tuple=True). > **Note** > > See also tensorplay.nonzero().