mindspore.Tensor.resize

mindspore.Tensor.resize(*new_shape)[源代码]

将Tensor改为输入的新shape,并将不足的元素补0。

说明

此方法不更改输入数组的大小,也不返回NumPy中的任何内容,而是返回一个具有输入大小的新Tensor。不支持Numpy参数 refcheck

参数:
  • new_shape (Union[ints, tuple of ints]) - 指定Tensor的新shape。

返回:

Tensor。

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor
>>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
>>> y = x.resize(3, 3)
>>> print(y)
[[1. 2. 3.]
[4. 5. 6.]
[0. 0. 0.]]
>>> y = x.resize(2, 2)
>>> print(y)
[[1. 2.]
[3. 4.]]