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.,
.- Returns
Tensor, If the given shape does not contain -1, the shape of tensor is
. If the k-th position in the given shape is -1, the shape of tensor is , in where the shape of input tensor is .
- 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]]