Rate this Page

torch.tile#

torch.tile(input,dims)Tensor#

Constructs a tensor by repeating the elements ofinput.Thedims argument specifies the number of repetitionsin each dimension.

Ifdims specifies fewer dimensions thaninput has, thenones are prepended todims until all dimensions are specified.For example, ifinput has shape (8, 6, 4, 2) anddimsis (2, 2), thendims is treated as (1, 1, 2, 2).

Analogously, ifinput has fewer dimensions thandimsspecifies, theninput is treated as if it were unsqueezed atdimension zero until it has as many dimensions asdims specifies.For example, ifinput has shape (4, 2) anddimsis (3, 3, 2, 2), theninput is treated as if it had theshape (1, 1, 4, 2).

Note

This function is similar to NumPy’s tile function.

Parameters
  • input (Tensor) – the tensor whose elements to repeat.

  • dims (tuple) – the number of repetitions per dimension.

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]])