SeeingML
Visual Math Toolkit Guide 3 of 6 · tap to switch
✦ Interactive Visual Guide 8 min · 4 hands-on labs · Beginner friendly

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%!

Interactive Lab 1: A Matrix Is a Space Warper
Start [2, 1] → Lands at [3, 1]
Step 1: Choose a space warp, then watch its two matrix columns move the East and North arrows.
Matrix A =
Col 1 (î)10
Col 2 (ĵ)11
East arrow (î) lands at [1, 0]North arrow (ĵ) lands at [1, 1]
Sample arrow [2, 1]: 2·[1, 0] + 1·[1, 1] = [3, 1]
Start [2, 1]î [1, 0]ĵ [1, 1][3, 1]East (+x)North (+y)(0,0)
100%
Slide Right (Shear): The East arrow (î) stays bolted at [1, 0], while the North arrow (ĵ) leans sideways to [1, 1]. Higher rows slide farther right, just like nudging a neat stack of playing cards.

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.

💡 Insight

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 stamped F still faces forward.
  • Negative (det(A) < 0): The rubber sheet flipped inside-out like looking in a mirror, so the F reads 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!

Interactive Lab 2: Determinant = Area Stretch & Mirror Check
Normal Orientation (Area × 3.00)
Quick tests (or drag any slider below): watch the stamped letter F inside the 1×1 square!
A =
2.00.0
1.01.5
det(A) = width (2.0) × height (1.5) = 3.00
Dashed 1×1 sticker (Area 1.0) → Shaded shape (Area 3.00, facing forward)
East (+x)North (+y)Dashed square = original 1×1 forward F
2.0
1.5
1.0
Normal Orientation (det = +3.00): The letter F still faces forward, and every 2D region scales by 3.00×. Try dragging shear (b) back and forth: the square leans dramatically, yet det(A) stays glued at 3.00! Then try flipping width negative to mirror the F, or setting height to 0 to squash it 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 · x means: apply Rotate (R) first, then Shear (S) second.
  • R · S · x means: 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!

Interactive Lab 3: Order Matters (Why S·R ≠ R·S)
Start arrow x = [2, 1]
Playback:
Teal Path (S·R): Rotate 90° first, then Shear
[2, 1] → Step 1: [-1, 2] → Final: [1, 2] (top-right)
Amber Path (R·S): Shear first, then Rotate 90°
[2, 1] → Step 1: [3, 1] → Final: [-1, 3] (top-left)
top-lefttop-right(0,0)Start [2, 1]Step 1 (Rotate): [-1, 2]Step 1 (Shear): [3, 1]
After Step 1, the paths already split! Rotating first swung the teal arrow into the top-left at [-1, 2], while shearing first slid the amber arrow farther right to [3, 1]. Click Apply Step 2 → to watch where both orders finally land!

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:

  1. Write the two shapes side by side: (B, d_in) @ (d_in, d_out).
  2. The two inner numbers (d_in and d_in) must match identically so every feature in a row of X pairs up one-to-one with a weight in a column of W.
  3. 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.

Interactive Lab 4: Inside a Neural Network Layer (The Golden Shape Rule)
Start with the small countable toy layer, test a shape mismatch bug, then jump to real GPT layer scale!
Input Table X(4, 4)4 rows4 cols@Weight Grid W(4, 3)4 rows3 colsInner Match: 4 = 4 (Cancels!)=Output Table Y(4, 3)4 × 3 outputs
Output Table Shape(4, 3)
Layer Weights (+ Bias)15 params
Parallel Multiply-Adds48 ops
Batch Examples (B)
Input Features (d_in)
Output Neurons (d_out)
Count it by eye! Multiplying (4, 4) @ (4, 3) matches the inner 4s and leaves a (4, 3) output table (4 examples × 3 output scores = 48 total multiply-adds). Now click Jump to GPT Scale to see why AI runs on GPUs!
See Matrix Product Definition, Determinant Formula & Transpose RulesThesis / Reference

1. Matrix Product as Row-by-Column Dot Products: For A∈Rm×k\mathbf{A} \in \mathbb{R}^{m \times k} and B∈Rk×n\mathbf{B} \in \mathbb{R}^{k \times n}, every entry of C=AB∈Rm×n\mathbf{C} = \mathbf{A}\mathbf{B} \in \mathbb{R}^{m \times n} is the dot product of row ii of A\mathbf{A} with column jj of B\mathbf{B}:

Cij=∑r=1kAirBrjC_{ij} = \sum_{r=1}^{k} A_{ir} B_{rj}

2. 2×2 Determinant & Inverse: For A=[abcd]\mathbf{A} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}, det⁡(A)=ad−bc\det(\mathbf{A}) = ad - bc. When det⁡(A)≠0\det(\mathbf{A}) \neq 0, the exact inverse exists:

A−1=1ad−bc[d−b−ca]\mathbf{A}^{-1} = \frac{1}{ad - bc} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

3. Reversal Rule for Transposes & Inverses: Reversing a chain of transformations unrolls in reverse order: (AB)⊤=B⊤A⊤(\mathbf{A}\mathbf{B})^\top = \mathbf{B}^\top \mathbf{A}^\top and (AB)−1=B−1A−1(\mathbf{A}\mathbf{B})^{-1} = \mathbf{B}^{-1} \mathbf{A}^{-1}.

See Matrix Multiplication & Determinants in NumPy / PyTorchOptional Code
python
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.0

Which 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.

✓ Self-Check

Quick Intuition Check

Four quick real-world scenarios. No scores, just test your intuition.

1

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?

Pick an option first, or peek anytime
2

A 2x2 matrix A has det(A) = 0. What happens geometrically to the 2D plane when you apply A to every point?

Pick an option first, or peek anytime
3

For any two square matrices A and B, multiplying A @ B always gives the exact same space warp as B @ A.

Pick an option first, or peek anytime
4

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?

Pick an option first, or peek anytime
Quick Reference

Common Questions

What does a matrix actually DO geometrically?
A matrix is a linear transformation that warps space while keeping grid lines straight, parallel, and evenly spaced with the origin fixed. Its columns simply record where the unit basis arrows i-hat and j-hat land after the warp.
What does a Determinant of 0 mean?
The Determinant measures how much a matrix scales area (in 2D) or volume (in 3D). When det(A) = 0, the matrix squashes space flat into a lower dimension (zero area), crushing infinitely many inputs onto the same line so no inverse matrix A^-1 can exist.
Why is Matrix Multiplication not commutative (A*B != B*A)?
Because multiplying matrices chains transformations sequentially (right-to-left). Rotating 90 degrees and then shearing horizontal lines produces a completely different landing position than shearing first and then rotating 90 degrees.
How do you check if two matrices can be multiplied in PyTorch or NumPy?
Write their shapes side by side: (M, K) @ (K, N). The two inner dimensions (K and K) must match identically so row-by-column dot products align, and the outer dimensions give the exact output shape (M, N).

Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference

https://seeingml.com/learn/matrix-multiplication/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@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}
}
APA

Irshad, M. A. (2026). Matrices & Matrix Multiplication: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/matrix-multiplication/