# tensorplay.functional.squeeze Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.squeeze.html ```python tensorplay.functional.squeeze(input: Tensor, dim: int | List[int] | None) → Tensor ``` Returns a tensor with all specified 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 input.squeeze() 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(s). 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. > **Warning** > > If the tensor has a batch dimension of size 1, then squeeze(input) will also remove the batch dimension, which can lead to unexpected errors. Consider specifying only the dims you wish to be squeezed. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – if given, the input will be squeezedonly in the specified dimensions. Changed in version 2.0: dim now accepts tuples of dimensions. Example: ``` >>> x = tensorplay.zeros(2, 1, 2, 1, 2) >>> x.size() tensorplay.Size([2, 1, 2, 1, 2]) >>> y = tensorplay.squeeze(x) >>> y.size() tensorplay.Size([2, 2, 2]) >>> y = tensorplay.squeeze(x, 0) >>> y.size() tensorplay.Size([2, 1, 2, 1, 2]) >>> y = tensorplay.squeeze(x, 1) >>> y.size() tensorplay.Size([2, 2, 1, 2]) >>> y = tensorplay.squeeze(x, (1, 2, 3)) tensorplay.Size([2, 2, 2]) ```