repeat¶
- tripy.repeat(input: Tensor, repeats: int | DimensionSize, dim: int) Tensor [source]¶
Repeats each element of a tensor after itself along the specified dimension.
- Parameters:
input (Tensor) – The input tensor.
repeats (int | DimensionSize) – The number of times to repeat each element.
dim (int) – The dimension along which to repeat values.
- Returns:
The new tensor.
- Return type:
Example: 1D tensor
1inp = tp.arange(4, dtype=tp.int32) 2out0 = tp.repeat(inp, 2, dim=0)
>>> inp tensor([0, 1, 2, 3], dtype=int32, loc=gpu:0, shape=(4,)) >>> out0 tensor([0, 0, 1, 1, 2, 2, 3, 3], dtype=int32, loc=gpu:0, shape=(8,))
Example: 2D tensor
1inp = tp.reshape(tp.arange(4, dtype=tp.int32), (2, 2)) 2out0 = tp.repeat(inp, 2, dim=0) 3out1 = tp.repeat(inp, 2, dim=1)
>>> inp tensor( [[0, 1], [2, 3]], dtype=int32, loc=gpu:0, shape=(2, 2)) >>> out0 tensor( [[0, 1], [0, 1], [2, 3], [2, 3]], dtype=int32, loc=gpu:0, shape=(4, 2)) >>> out1 tensor( [[0, 0, 1, 1], [2, 2, 3, 3]], dtype=int32, loc=gpu:0, shape=(2, 4))