mindspore.ops.repeat_elements
- mindspore.ops.repeat_elements(x, rep, axis=0)[source]
Repeat elements of a tensor along an axis, like numpy.repeat .
Note
It is recommended to use :func:'mindspore.mint.repeat_interleave', the dimension of input 'x' can support a maximum of 8, and get better performance.
- Parameters
- Returns
One tensor with values repeated along the specified axis. If x has shape \((s1, s2, ..., sn)\) and axis is i, the output will have shape \((s1, s2, ..., si * rep, ..., sn)\). The output type will be the same as the type of x.
- Raises
ValueError – If the rank of x is greater than 7.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> # case 1 : repeat on axis 0 >>> x = Tensor(np.array([[0, 1, 2], [3, 4, 5]]), mindspore.int32) >>> output = ops.repeat_elements(x, rep = 2, axis = 0) >>> print(output) [[0 1 2] [0 1 2] [3 4 5] [3 4 5]] >>> # case 2 : repeat on axis 1 >>> x = Tensor(np.array([[0, 1, 2], [3, 4, 5]]), mindspore.int32) >>> output = ops.repeat_elements(x, rep = 2, axis = 1) >>> print(output) [[0 0 1 1 2 2] [3 3 4 4 5 5]]