fn
where
→Tensorwhere(cond: Tensor, x: Tensor, y: Tensor)Elementwise selection between x and y based on cond.
For each element position the result is x where cond is
True and y otherwise. All three inputs broadcast against each
other.
Parameters
condTensorBoolean tensor.
xTensorValues used where
cond is True.yTensorValues used where
cond is False.Returns
TensorTensor of the broadcast shape.
Notes
Mathematically,
Differentiable through both x and y — the gradient is gated
by cond.
Examples
>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([-1.0, -2.0, -3.0])
>>> lucid.where(a > 1.5, a, b)
Tensor([-1., 2., 3.])