
Last chance! 50% off unlimited learning
Sale ends in
Squeeze
torch_squeeze(self, dim)
(Tensor) the input tensor.
(int, optional) if given, the input will be squeezed only in this dimension
Returns a tensor with all the dimensions of input
of size 1
removed.
For example, if input
is of shape:
out
tensor
will be of shape:
When dim
is given, a squeeze operation is done only in the given
dimension. If input
is of shape: squeeze(input, 0)
leaves the tensor unchanged, but squeeze(input, 1)
will squeeze the tensor to the shape
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
}
Run the code above in your browser using DataLab