Broadcasting Rules That Save You Loops
Combine different-shaped tensors elementwise.
Combine Without Matching Shapes
Broadcasting lets PyTorch stretch a smaller tensor to fit a bigger one, so you skip writing loops to repeat values.
Add a Scalar to Everything
The simplest broadcast: add one number to a whole tensor. PyTorch applies it to every element at once. ✨
x = torch.tensor([1, 2, 3])
print(x + 10) # tensor([11, 12, 13])All lessons in this course
- Shapes, Dtypes & Indexing
- Reshape, View, Squeeze & Unsqueeze
- Broadcasting Rules That Save You Loops
- Tensors Talk to NumPy