Visual Math Toolkit Guide 3 of 6 · tap to switch
Matrices & Matrix Multiplication
See a matrix as a live space-warping machine, watch the Determinant scale or squash area, and master PyTorch layer shapes.
Most textbooks introduce a matrix as a lifeless rectangle of numbers and immediately force you to memorize a row-by-column arithmetic dance. No wonder beginners get lost! Visually, a matrix is much simpler: it is a space-warping machine, and matrix multiplication is simply chaining two warps one after another.
Picture a stretchy rubber sheet printed with a square grid and pinned down at the center (0, 0). To describe any flat stretch, rotation, or tilt of that entire sheet, you only need to track two tiny reference arrows starting from the center:
- The East 1-step arrow, pointing 1 step right (
[1, 0]), which math callsî(pronounced “i-hat”). - The North 1-step arrow, pointing 1 step up (
[0, 1]), which math callsĵ(pronounced “j-hat”).
A 2×2 matrix is simply a two-column instruction card for those two arrows. Column 1 (the left vertical column) tells the East arrow î where to land, and Column 2 (the right vertical column) tells the North arrow ĵ where to land. Every other arrow on the grid simply rides along on the same rubber sheet! For example, the sample arrow [2, 1] means “walk 2 copies of the East arrow plus 1 copy of the North arrow”, so after the warp it lands at 2 copies of Column 1 plus 1 copy of Column 2.
One classic warp you will see right away below is a sideways slide: imagine a neat deck of playing cards resting on a table. Keep the bottom card glued in place and nudge the rest of the deck sideways so each higher card slides a little farther right. Mathematicians call that sideways leaning tilt a shear. Pick any warp below, read its color-coded columns, and scrub the slider from 0% to 100%!
Notice the two strict rules every warp above obeyed: grid lines stay straight and parallel, and the center (0, 0) stays bolted down. Mathematicians call any warp following those two rules a linear transformation.
Why neural networks need more than matrices: Because a matrix can only stretch, rotate, or tilt straight lines without curving them, stacking matrix layers alone still only produces straight lines. That is why every neural network inserts a bending step called an Activation Function after each matrix layer so the model can learn curves!
The Determinant: how much did space stretch (or crush)?
Look back at the shaded 1×1 square in Lab 1: Stretch 2× made it grow 4 times larger, Slide Right (Shear) tilted it without changing its area, and Flatten to a Line squashed it completely flat!
Imagine placing a 1×1 square sticker (area = 1) on our rubber sheet, stamped with an asymmetric uppercase letter F so we can tell if the sheet ever flips backwards. When a matrix warps the sheet, we want one single number that measures both how much the area stretched and whether the sheet flipped over like a mirror reflection. That single number is the Determinant, written det(A):
- Positive (
det(A) > 0): The square stretches or shrinks, and the stampedFstill faces forward. - Negative (
det(A) < 0): The rubber sheet flipped inside-out like looking in a mirror, so theFreads backwards! (The area size is the number without the minus sign.) - Zero (
det(A) = 0): The entire 2D plane gets crushed flat onto a 1D line (or a single center dot), wiping its area down to 0!
Try the quick tests or drag the width, height, and shear sliders below to watch the stamped F stretch, flip backwards, and squash flat!
As long as area never drops to zero (det(A) ≠ 0), you can play the warp in reverse using an undo matrix called the inverse (A⁻¹). But the moment det(A) = 0, infinitely many distinct points get smashed on top of each other onto the exact same flat line, so no undo matrix can ever tell where each crushed point started. Mathematicians call a zero-determinant, non-undoable matrix singular (or non-invertible).
Matrix Multiplication = Chaining Two Warps (Order Matters!)
Think about getting dressed in the morning: putting on socks first, then shoes works great. Reversing the order (shoes first, then socks) leaves your socks stretched over the outside of your shoes!
Chaining two geometric warps works the exact same way. Suppose we start with an arrow x = [2, 1] and want to apply two moves: Rotate 90° (R) and Slide Right / Shear (S). Instead of running two separate warps every time, matrix multiplication fuses both moves into one single combined matrix.
Just like wrapping a gift inside a box (outer(inner(gift))), math reads a chain of matrices right-to-left, applying whichever matrix sits closest to x first:
S · R · xmeans: apply Rotate (R) first, then Shear (S) second.R · S · xmeans: apply Shear (S) first, then Rotate (R) second.
Because swapping the order sends the arrow to a totally different destination (S · R ≠ R · S), mathematicians say matrix multiplication is non-commutative (order matters!). Click Apply Step 2 below to watch both orders unfold one step at a time instead of teleporting!
Why GPUs run Deep Learning on Matrix Multiplication
In Python and machine learning code, we write the @ symbol between two tables to mean “matrix-multiply these two grids” (keeping it distinct from *, which just multiplies matching slots element by element).
You might notice one small notation twist between math class and AI code. In geometry and textbooks, you usually transform a single arrow standing upright as a vertical column, so the matrix sits on the left: A · x. Inside a Neural Network layer, however, you do not transform one example at a time in a slow loop. Instead, you stack an entire batch of B examples like rows in a spreadsheet to form an input table X of shape (B, d_in) (Batch examples × Input features). Because each input example now lies horizontally as a row instead of standing upright as a column, the layer’s weight grid W moves to the right side: X @ W!
To know whether two grids can be multiplied (and what output shape comes out), use the Golden Shape Rule:
- Write the two shapes side by side:
(B, d_in) @ (d_in, d_out). - The two inner numbers (
d_inandd_in) must match identically so every feature in a row ofXpairs up one-to-one with a weight in a column ofW. - Those matching inner numbers cancel out, leaving the outer numbers as the output shape:
(B, d_out).
For example, a tiny toy layer with 4 examples and 4 input features multiplied by a 4 × 3 weight grid gives (4, 4) @ (4, 3) = (4, 3). Scale that exact same rule up to a real Transformer layer and (32, 768) @ (768, 3072) produces (32, 3072) in a single parallel blast on a graphics chip (GPU)!
Start on the countable 4×4 toy layer below, click Test Shape Mismatch Bug to see what breaks when the inner numbers clash, and then click Jump to GPT Scale.
See Matrix Product Definition, Determinant Formula & Transpose RulesThesis / Reference
1. Matrix Product as Row-by-Column Dot Products: For and , every entry of is the dot product of row of with column of :
2. 2×2 Determinant & Inverse: For , . When , the exact inverse exists:
3. Reversal Rule for Transposes & Inverses: Reversing a chain of transformations unrolls in reverse order: and .
See Matrix Multiplication & Determinants in NumPy / PyTorchOptional Code
import numpy as np
R = np.array([[0, -1], [1, 0]]) # Rotate 90 deg CCW
S = np.array([[1, 1], [0, 1]]) # Horizontal shear
x = np.array([2, 1])
print("S @ R @ x =", S @ R @ x) # [ 1, 2]
print("R @ S @ x =", R @ S @ x) # [-1, 3] (Different!)
print("det(S @ R) =", round(np.linalg.det(S @ R), 2)) # 1.0Which special arrows refuse to spin when space warps?
When a matrix stretches, rotates, and shears a 2D plane, almost every arrow gets knocked sideways off its original line. Yet a few special arrows stay glued to their exact own line, only stretching or shrinking!
Those special un-spun directions are called Eigenvectors, and they power PCA, PageRank, and graph machine learning. Next up: Eigenvectors & Eigenvalues.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
An input table X holds 32 examples with 768 features each, giving shape (32, 768). You matrix-multiply it by a layer weight grid W of shape (768, 3072). What is the output shape of X @ W?
A 2x2 matrix A has det(A) = 0. What happens geometrically to the 2D plane when you apply A to every point?
For any two square matrices A and B, multiplying A @ B always gives the exact same space warp as B @ A.
Suppose a 2x2 matrix A has top row [3, -1] and bottom row [2, 4]. Where does the East 1-step arrow i-hat = [1, 0] land after applying A?
Common Questions
What does a matrix actually DO geometrically?
What does a Determinant of 0 mean?
Why is Matrix Multiplication not commutative (A*B != B*A)?
How do you check if two matrices can be multiplied in PyTorch or NumPy?
Related Visual Guides
Neural Networks & the Perceptron
Demystify neural networks from a single weighted switch to multi-layer perceptrons that solve XOR and approximate any curve.
Eigenvalues and Eigenvectors
Spin a probe arrow to catch the rare directions that refuse to tilt under a matrix warp, and see why they power PCA and PageRank.
Convolutional Neural Networks (CNNs)
See how sliding 3x3 magnifying filters, stride, padding, and pooling let neural networks recognize visual patterns anywhere in an image.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026matrixmultiplication,
author = {Irshad, Muhammad Aashir},
title = {Matrices & Matrix Multiplication: Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/matrix-multiplication/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). Matrices & Matrix Multiplication: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/matrix-multiplication/