mindspore.Tensor.resize
- Tensor.resize(*new_shape)[source]
Changes shape and size of tensor in-place.
If the shape of the new tensor is larger than the shape of the original tensor, the new tensor will be filled with 0. And if the shape of the new tensor is smaller than the shape of the original tensor, the new tensor is filled with the elements of the original tensor in order.
Note
Instead of changing the size of the input tensor and returns nothing as in numpy, this method returns a new Tensor with the input size. Numpy argument refcheck is not supported.
- Parameters
new_shape (Union[ints, tuple of ints]) – Shape of resized tensor.
- Returns
Tensor.
- Supported Platforms:
Ascend
GPU
CPU
See also
mindspore.Tensor.reshape()
: Give a new shape to a tensor without changing its data.mindspore.Tensor.repeat()
: Repeat elements of a tensor.Examples
>>> 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.]]