PyTorch .tile()
Published Feb 8, 2025
Contribute to Docs
In PyTorch, the torch.tile() function generates a new tensor by repeating the elements of an existing tensor along specified dimensions. This function is available in the torch module and allows element-wise repetition along multiple dimensions.
Syntax
torch.tile(input, dims)
input: The input tensor to be repeated.dims: A tuple specifying the number of times the tensor is to be repeated along each dimension. The length ofdimsmust match the number of dimensions ininput.
Example
The following example demonstrates the usage of the .tile() function:
import torch# Define a tensorten = torch.tensor([13, 24, 35, 46])# Repeat the tensor 2 times along the first dimension and 3 times along the second dimensionres = torch.tile(ten, (2, 3))# Print the resultprint(res)
The above code produces the following output:
tensor([[13, 24, 35, 46, 13, 24, 35, 46, 13, 24, 35, 46],[13, 24, 35, 46, 13, 24, 35, 46, 13, 24, 35, 46]])
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours