squeeze

tripy.squeeze(input: Tensor, dims: Tuple | int) Tensor[source]

Returns a new tensor with all specified singleton dimensions of the input tensor removed.

Parameters:
  • input (Tensor) – [dtype=T1] The input tensor.

  • dims (Tuple | int) – The singleton dimensions to be removed. If this is not provided, all dimensions of size 1 are removed.

Raises:

TripyException – If any of the specified dimensions have a size that is not equal to 1.

Returns:

[dtype=T1] A new tensor.

Return type:

Tensor

TYPE CONSTRAINTS:
Example: Squeeze All Dimensions
Squeeze All Dimensions
1input = tp.iota((1, 2, 1), dtype=tp.float32)
2output = tp.squeeze(input, dims=(0, 2))
>>> input
tensor(
    [[[0.0000],
      [0.0000]]], 
    dtype=float32, loc=gpu:0, shape=(1, 2, 1))
>>> output
tensor([0.0000, 0.0000], dtype=float32, loc=gpu:0, shape=(2,))
Example: Squeeze First Dimension
Squeeze First Dimension
1input = tp.iota((1, 2, 1), dtype=tp.float32)
2output = tp.squeeze(input, 0)
>>> input
tensor(
    [[[0.0000],
      [0.0000]]], 
    dtype=float32, loc=gpu:0, shape=(1, 2, 1))
>>> output
tensor(
    [[0.0000],
     [0.0000]], 
    dtype=float32, loc=gpu:0, shape=(2, 1))
Example: Squeeze First And Third Dimension
Squeeze First And Third Dimension
1input = tp.iota((1, 2, 1), dtype=tp.float32)
2output = tp.squeeze(input, (0, 2))
>>> input
tensor(
    [[[0.0000],
      [0.0000]]], 
    dtype=float32, loc=gpu:0, shape=(1, 2, 1))
>>> output
tensor([0.0000, 0.0000], dtype=float32, loc=gpu:0, shape=(2,))