torch_where: Where

Description Usage Arguments where(condition, x, y) -> Tensor where(condition) -> tuple of LongTensor Note Examples

View source: R/gen-namespace.R

Description

Where

Usage

1
torch_where(condition, self, other)

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 = ≤ft\{ \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

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

See also torch_nonzero().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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 Oct. 7, 2021, 9:22 a.m.