giagrad.Tensor.squeeze#
- Tensor.squeeze(axis=None)[source]#
Remove axes of length one.
For example, a tensor of shape \((1, N_1, N_2, 1, N_3, 1)\) will be reshaped into \((N_1, N_2, N_3)\) if no axis is inputed. Specific axis with length one can be removed either passing an int or a tuple or ints.
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
will also remove the batch dimension, which can lead to unexpected errors. Consider specifying only the dims you wish to be squeezed.See also
- Parameters:
axis¶ ((int, ...) or int, optional) – By default removes all axes of length one, if tuple or int passed those axes will be removed.
Examples
>>> t = Tensor.empty(1, 2, 1, 2, 1).uniform() >>> t tensor: [[[[[0.16217469] [0.8090288 ]]] ... ... [[[0.7216649 ] [0.6690301 ]]]]] >>> t.squeeze() tensor: [[0.16217469 0.8090288 ] [0.7216649 0.6690301 ]] fn: Squeeze(axis = None) >>> t.squeeze().shape (2, 2)