mindspore.ops.reshape

查看源文件
mindspore.ops.reshape(input, shape)[源代码]

按指定 shape ,对输入tensor进行重排。

说明

参数 shape 中的-1表示该维度值是从其他维度和输入的元素数量推断出来的。

参数:
  • input (Tensor) - 输入tensor。

  • shape (Union[tuple[int], list[int], Tensor[int]]) - 新shape。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> 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]]