mindspore.Tensor.repeat

Tensor.repeat(repeats, axis=None)[source]

Repeat elements of a tensor.

Parameters
  • repeats (Union[int, tuple, list]) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.

  • axis (int, optional) – The axis along which to repeat values. By default, use the flattened input tensor, and return a flat output tensor. Default: None.

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.

Supported Platforms:

Ascend GPU CPU

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.

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]]