Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

torch_squeeze

Squeeze


Description

Squeeze

Usage

torch_squeeze(self, dim)

Arguments

self

(Tensor) the input tensor.

dim

(int, optional) if given, the input will be squeezed only in this dimension

squeeze(input, dim=NULL, out=NULL) -> Tensor

Returns a tensor with all the dimensions of input of size 1 removed.

For example, if input is of shape: (A \times 1 \times B \times C \times 1 \times D) then the out tensor will be of shape: (A \times B \times C \times D).

When dim is given, a squeeze operation is done only in the given dimension. If input is of shape: (A \times 1 \times B), squeeze(input, 0) leaves the tensor unchanged, but squeeze(input, 1) will squeeze the tensor to the shape (A \times B).

Note

The returned tensor shares the storage with the input tensor, so changing the contents of one will change the contents of the other.

Examples

if (torch_is_installed()) {

x = torch_zeros(c(2, 1, 2, 1, 2))
x
y = torch_squeeze(x)
y
y = torch_squeeze(x, 1)
y
y = torch_squeeze(x, 2)
y
}

torch

Tensors and Neural Networks with 'GPU' Acceleration

v0.3.0
MIT + file LICENSE
Authors
Daniel Falbel [aut, cre, cph], Javier Luraschi [aut], Dmitriy Selivanov [ctb], Athos Damiani [ctb], Christophe Regouby [ctb], Krzysztof Joachimiak [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.