reshape

tripy.reshape(input: Tensor, shape: Sequence[int | DimensionSize]) Tensor[source]

Returns a new tensor with the contents of the input tensor in the specified shape.

Parameters:
  • input (Tensor) – The input tensor.

  • shape (Sequence[int | DimensionSize]) – The desired compatible shape. If a shape dimension is -1, its value is inferred based on the other dimensions and the number of elements in the input. Atmost one dimension can be -1.

Returns:

A new tensor with the specified shape.

Return type:

Tensor

Example
Example
1input = tp.iota((2, 3), dtype=tp.float32)
2output = tp.reshape(input, (1, 6))
>>> input
tensor(
    [[0.0000, 0.0000, 0.0000],
     [1.0000, 1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(2, 3))
>>> output
tensor(
    [[0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000]], 
    dtype=float32, loc=gpu:0, shape=(1, 6))