We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Matmul and einsum
PyTorchExpress matrix products, batch dimensions and tensor contractions with matmul and einsum. Check dimension labels and broadcasting before computing a result.
6 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. One weight matrix, every item Practice · Easy
- 2 Not solved yet. Queries against keys Practice · Medium
- 3 Not solved yet. Subscripts instead of transposes Practice · Medium
- 4 Not solved yet. Elementwise or matrix multiplication? Practice · Easy
- 5 Not solved yet. Choose the order of matrix multiplications Practice · Medium
- 6 Not solved yet. One matrix, many batches Practice · Easy
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
What happens in these two operations on matrices with shapes (2, 3) and (3, 4)?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
import torch
a = torch.ones(2, 3)
b = torch.ones(3, 4)
print((a @ b).shape)
try:
a * b
except RuntimeError:
print("RuntimeError")