mindspore.ops.reshape

View Source On AtomGit
mindspore.ops.reshape(input, shape)[source]

Reshape the input tensor based on the given shape.

Note

The -1 in the parameter shape indicates that the size of that dimension is inferred from the other dimensions and the total number of elements in the input tensor.

Parameters
Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]], mindspore.float32)
>>> # case1: Parameter `shape` does not contain -1.
>>> output = mindspore.ops.reshape(input, (3, 2))
>>> print(output)
[[-0.1  0.3]
 [ 3.6  0.4]
 [ 0.5 -3.2]]
>>> # case2: Parameter `shape` contains -1.
>>> output = mindspore.ops.reshape(input, (-1, 6))
>>> print(output)
[[-0.1  0.3  3.6  0.4  0.5 -3.2]]