The single most important operation in deep learning
Matrix multiplication is what makes neural networks fast. A forward pass through a linear layer is a matrix multiply. Running inference on a batch of 64 samples is a matrix multiply. The entire efficiency of GPU-accelerated deep learning comes from GPUs being exceptionally good at matrix multiplications. Without understanding this, you can't reason about model efficiency, memory, or batch processing.
Matrix multiplication is doing many dot products at once. If A has m rows and B has n columns, A×B produces an m×n matrix where entry (i,j) is the dot product of row i of A with column j of B.
The critical rule: inner dimensions must match. A(m×k) × B(k×n) → C(m×n). The outer dimensions become the result shape.
Each element C[i][j] = dot(row_i of A, col_j of B)
In practice, you always process batches. If X is (32, 256) and W is (256, 512), then X @ W produces (32, 512) — all 32 forward passes computed simultaneously. This is why GPUs are effective: they parallelize thousands of dot products at once.
In PyTorch: torch.matmul(X, W) or the @ operator. Know the shapes before you call it.