torch.tile¶
-
torch.
tile
(input, reps) → Tensor¶ Constructs a tensor by repeating the elements of
input
. Thereps
argument specifies the number of repetitions in each dimension.If
reps
specifies fewer dimensions thaninput
has, then ones are prepended toreps
until all dimensions are specified. For example, ifinput
has shape (8, 6, 4, 2) andreps
is (2, 2), thenreps
is treated as (1, 1, 2, 2).Analogously, if
input
has fewer dimensions thanreps
specifies, theninput
is treated as if it were unsqueezed at dimension zero until it has as many dimensions asreps
specifies. For example, ifinput
has shape (4, 2) andreps
is (3, 3, 2, 2), theninput
is treated as if it had the shape (1, 1, 4, 2).Note
This function is similar to NumPy’s tile function.
- Parameters
Example:
>>> x = torch.tensor([1, 2, 3]) >>> x.tile((2,)) tensor([1, 2, 3, 1, 2, 3]) >>> y = torch.tensor([[1, 2], [3, 4]]) >>> torch.tile(y, (2, 2)) tensor([[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]])