mindspore.Tensor.reshapeο
- Tensor.reshape(*shape)[source]ο
Rearranges the input Tensor based on the given shape .
The shape can only have one -1 at most, in which case itβs inferred from the remaining dimensions and the number of elements in the input.
- Parameters
shape (Union[int, tuple[int], list[int]]) β If shape is a tuple or list, its elements should be integers, and only constant value is allowed. i.e., \((y_1, y_2, ..., y_S)\).
- Returns
Tensor, If the given shape does not contain -1, the shape of tensor is \((y_1, y_2, ..., y_S)\). If the k-th position in the given shape is -1, the shape of tensor is \((y_1, ..., y_{k-1}, \frac{\prod_{i=1}^{R}x_{i}}{y_1\times ...\times y_{k-1}\times y_{k+1}\times...\times y_S} , y_{k+1}, ..., y_S)\), in where the shape of input tensor is \((x_1, x_2, ..., x_R)\).
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> input = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32) >>> output = input.reshape(3, 2) >>> print(output) [[-0.1 0.3] [ 3.6 0.4] [ 0.5 -3.2]]