powered by
Where
(BoolTensor) When True (nonzero), yield x, otherwise yield y
(Tensor) values selected at indices where condition is True
condition
True
(Tensor) values selected at indices where condition is False
False
Return a tensor of elements selected from either x or y, depending on condition.
x
y
The operation is defined as:
$$ \mbox{out}_i = \left\{ \begin{array}{ll} \mbox{x}_i & \mbox{if } \mbox{condition}_i \\ \mbox{y}_i & \mbox{otherwise} \\ \end{array} \right. $$
torch_where(condition) is identical to torch_nonzero(condition, as_tuple=True).
torch_where(condition)
torch_nonzero(condition, as_tuple=True)
# NOT RUN { if (torch_is_installed()) { # } # NOT RUN { x = torch_randn(c(3, 2)) y = torch_ones(c(3, 2)) x torch_where(x > 0, x, y) # } # NOT RUN { } # }
Run the code above in your browser using DataLab