torch_where: Where

View source: R/wrapers.R

torch_whereR Documentation

Where

Description

Where

Usage

torch_where(condition, self = NULL, other = NULL)

Arguments

condition

(BoolTensor) When TRUE (nonzero), yield x, otherwise yield y

self

(Tensor) values selected at indices where condition is TRUE

other

(Tensor) values selected at indices where condition is FALSE

where(condition, x, y) -> Tensor

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

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.

where(condition) -> tuple of LongTensor

torch_where(condition) is identical to torch_nonzero(condition, as_tuple=TRUE).

Note

The tensors `condition`, `x`, `y` must be broadcastable .

See also torch_nonzero().

Examples

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)

## End(Not run)



}

torch documentation built on June 7, 2023, 6:19 p.m.