mindspore.ops.repeat_interleave

View Source On Gitee
mindspore.ops.repeat_interleave(input, repeats, axis=None)[source]

Repeat elements of a tensor along an axis, like mindspore.numpy.repeat().

Parameters
  • input (Tensor) – The input tensor.

  • repeats (Union[int, tuple, list, Tensor]) – The number of times to repeat, must be positive.

  • axis (int, optional) – The axis along which to repeat, Default None. if dims is None, both the input and output tensors will be flattened into 1-D.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>>  # case 1 : repeat on axis 0
>>> input = mindspore.tensor([[0, 1, 2], [3, 4, 5]], mindspore.int32)
>>> output = mindspore.ops.repeat_interleave(input, repeats=2, axis=0)
>>> print(output)
[[0 1 2]
 [0 1 2]
 [3 4 5]
 [3 4 5]]
>>>  # case 2 : repeat on axis 1
>>> input = mindspore.tensor([[0, 1, 2], [3, 4, 5]], mindspore.int32)
>>> output = mindspore.ops.repeat_interleave(input, repeats=2, axis=1)
>>> print(output)
[[0 0 1 1 2 2]
[3 3 4 4 5 5]]