mindspore.ops.reshape
- mindspore.ops.reshape(input_x, input_shape)[source]
Rearranges the input Tensor based on the given shape.
The ‘input_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
- Returns
Tensor, the shape of tensor is \((y_1, y_2, ..., y_S)\).
- Raises
ValueError – Given a shape tuple, if it has several -1; or if the product of its elements is less than or equal to 0 or cannot be divided by the product of the input tensor shape; or if it does not match the input’s array size.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32) >>> output = ops.reshape(input_x, (3, 2)) >>> print(output) [[-0.1 0.3] [ 3.6 0.4] [ 0.5 -3.2]]