mindspore.mint.repeat_interleave

mindspore.mint.repeat_interleave(input, repeats, dim=None, *, output_size=None) Tensor[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.

  • dim (int, optional) – The dim along which to repeat. Default None, which means the input tensor will be flattened and the output will also be flattened.

Keyword Arguments

output_size (int, optional) – Total output size for the given axis (e.g. sum of repeats ). Default None.

Returns

Tensor, values repeated along the specified dimension. If input has shape \((s1, s2, ..., sn)\) and dim is i, the output will have shape \((s1, s2, ..., si * repeats, ..., sn)\). The output type will be the same as the type of input.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> input = mindspore.tensor([[0, 1, 2], [3, 4, 5]])
>>> mindspore.mint.repeat_interleave(input, repeats=2, dim=0)
    Tensor(shape=[4, 3], dtype=Int64, value=
    [[0, 1, 2],
     [0, 1, 2],
     [3, 4, 5],
     [3, 4, 5]])
>>> mindspore.mint.repeat_interleave(input, repeats=[1,2], dim=0)
    Tensor(shape=[3, 3], dtype=Int64, value=
    [[0, 1, 2],
     [3, 4, 5],
     [3, 4, 5]])
>>> mindspore.mint.repeat_interleave(input, repeats=2, dim=1)
    Tensor(shape=[2, 6], dtype=Int64, value=
    [[0, 0, 1, 1, 2, 2],
     [3, 3, 4, 4, 5, 5]])
>>> mindspore.mint.repeat_interleave(input, repeats=[1,2], dim=0, output_size=3)
    Tensor(shape=[3, 3], dtype=Int64, value=
    [[0, 1, 2],
     [3, 4, 5],
     [3, 4, 5]])