mindspore.Tensor.reshape
- mindspore.Tensor.reshape(*shape)[源代码]
基于给定的 shape ,对输入Tensor进行重新排列。
shape 最多只能有一个-1,在这种情况下,它可以从剩余的维度和输入的元素个数中推断出来。
- 参数:
shape (Union[int, tuple[int], list[int]]) - 如果 shape 是list或者tuple,其元素需为整数,并且只支持常量值。 如
。
- 返回:
Tensor,若给定的 shape 中不包含-1, 则输出 shape 为
。若给定的 shape 中第 k 个位置 为-1,则输出 shape 为 ,其中输入Tensor的 shape 为 。- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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]]