mindspore.Tensor.repeat
- Tensor.repeat(repeats, axis=None)[source]
Repeat elements of a tensor.
- Parameters
- Returns
Tensor, has the same shape as input tensor except along the given axis.
- Raises
ValueError – If the axis is out of range.
TypeError – If arguments have types not specified above.
See also
mindspore.Tensor.reshape()
: Give a new shape to a tensor without changing its data.mindspore.Tensor.resize()
: Changes shape and size of tensor in-place.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array(3)) >>> print(x.repeat(4)) [3 3 3 3] >>> x = Tensor(np.array([[1, 2],[3, 4]])) >>> print(x.repeat(2)) [1 1 2 2 3 3 4 4] >>> print(x.repeat(3, axis=1)) [[1 1 1 2 2 2] [3 3 3 4 4 4]] >>> print(x.repeat([1,2], axis=0)) [[1 2] [3 4] [3 4]]