mindspore.mint.reshape
- mindspore.mint.reshape(input, shape)[源代码]
根据给定形状重新排列输入张量。
说明
参数 shape 中的
-1表示该维度的大小将根据其他维度和输入张量总元素数自动推导得出。- 参数:
input (Tensor) - 输入张量。
shape (Union[tuple[int], list[int], Tensor[int]]) - 新的形状。
- 返回:
Tensor
- 支持平台:
Ascend
样例:
>>> 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.mint.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.mint.reshape(input, (-1, 6)) >>> print(output) [[-0.1 0.3 3.6 0.4 0.5 -3.2]]