mindspore.ops.reshape

mindspore.ops.reshape(input, 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
  • input (Tensor) – The shape of tensor is \((x_1, x_2, ..., x_R)\).

  • shape (Union[tuple[int], Tensor[int]]) – Constructed by multiple integers, i.e., \((y_1, y_2, ..., y_S)\). Only constant value is allowed.

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 = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32)
>>> output = ops.reshape(input, (3, 2))
>>> print(output)
[[-0.1  0.3]
 [ 3.6  0.4]
 [ 0.5 -3.2]]