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

Vectors, Norms & Dot Products

See every ML data row and embedding as an arrow in space, add and scale vectors visually, and feel why Dot Products measure alignment.

Imagine texting a friend walking directions from a coffee shop to a park: “Walk 4 blocks East, then 3 blocks North.” You can write those directions as a tiny list of two numbers, [4, 3], or you can draw a straight arrow on a city map pointing from the coffee shop right to the park.

Those two pictures describe the exact same object. Mathematicians call it a vector: a list of numbers that is also a geometric arrow with a direction and a length (also called its magnitude). How long is that straight crow-flies arrow from [0, 0] to [4, 3]? By the classic right-triangle rule (Pythagoras), square each step, add them together, and take the square root: sqrt(4^2 + 3^2) = sqrt(25) = 5 blocks. (In math books, people often write the length of arrow v using double bars: ||v||.)

Why does this matter for machine learning? Computers cannot “see” a house, a song, or a movie review directly, so every ML system turns each item into a numbered list (a vector) like [size, bedrooms] or [action_score, comedy_score]. Once data becomes arrows on a map, simple geometry unlocks almost everything models do.

Slide the East/West and North/South steps below (try negative numbers to walk West or South!) and watch the list of numbers, the map arrow, and its straight-line length move together.

Interactive Lab 1: One Vector, Two Views
List: [4, 3]Arrow Length: 5.00
East (+x)West (-x)North (+y)South (-y)4 East3 North[4, 3] (len 5.00)
East/West step (x = 4)North/South step (y = 3)Straight-line arrow (length 5.00)
Slide either step (try negative values to walk West or South):
+4 (East)
+3 (North)
Walk 4 blocks East, then 3 blocks North. That list [4, 3] is the exact same object as the arrow pointing at 37° with straight-line Arrow Length sqrt(4^2 + 3^2) = sqrt(25) = 5.00 blocks. In machine learning, a 2-number list like this can store any pair of measurements, such as [House Size, Bedrooms] or [Action Score, Comedy Score].

Adding arrows & flipping direction

Once information lives as arrows on a map, two everyday moves build most of the math inside machine learning:

  • Adding two trips (u + v), called Vector Addition: Suppose you first walk along trip u ([3, 2]), and from where you land, you walk along a second trip v ([2, -3]). Putting the tail of the second arrow onto the tip of the first (“tip-to-tail”) lands you at the exact same spot as adding matching slots: [3 + 2, 2 + (-3)] = [5, -1].
  • Stretching, shrinking, or flipping (c · u), called Scalar Multiplication: In vector math, a plain single number like 2, 0.5, or -1 is called a scalar (because it scales an arrow). Multiply an arrow by 2 to double its length, or by 0.5 to cut it in half. Multiply by a negative scalar like -0.5 or -1, and the minus sign flips the arrow 180 degrees to point in the exact opposite direction!

That negative-scalar flip shows up constantly when models learn: in a training loop called Gradient Descent, a model multiplies an uphill direction arrow by a small negative scalar (like -0.1) to take a smooth step in the opposite, downhill direction.

Try both modes below. First move the second trip v in Add Two Trips mode to see the combined green shortcut update live. Then switch to Stretch or Flip mode and drag the scalar c smoothly across zero!

Interactive Lab 2: Add Two Trips or Stretch & Flip
Add two trips tip-to-tail:[3, 2] + [2, -3] = [5, -1]
u = [3, 2]v = [2, -3]u + v = [5, -1]
First trip u = [3, 2]Second trip v = [2, -3]Shortcut u + v = [5, -1]
Try a trip v:
2
-3
Add two trips tip-to-tail: start at [0, 0], walk along teal u = [3, 2], then follow dashed orange v = [2, -3]. You land at the green shortcut u + v = [5, -1], which matches adding slot-by-slot: [3 + 2, 2 + (-3)] = [5, -1].

The Dot Product: the single most important operation in AI

Suppose your movie taste is scored on two traits, [Action, Comedy], giving you the taste arrow u = [4, 0] (pure Action fan). When a recommendation system inspects a new movie’s arrow v, how does it score whether the movie matches your taste?

It uses the Dot Product (written u · v): multiply the matching slots of both lists and add them up, (u1 × v1) + (u2 × v2).

Here is the geometric magic behind that tiny arithmetic recipe: multiplying matching slots and adding them up ALWAYS equals (length of u) × (length of v) × cos(angle). Think of cos(angle) (the cosine of the angle between the two arrows) as a simple alignment dial running from -1 to +1:

  • cos(0°) = +1 when both arrows point the exact same way, producing the biggest positive score.
  • cos(90°) = 0 when they meet at a clean right angle, producing exact 0.
  • cos(180°) = -1 when they point in opposite directions, producing the biggest negative score.

Geometrically, multiplying the length of v by cos(angle) tells you how far v casts a shadow along u. Rotate arrow v through a full 360° circle below and watch the slot-by-slot arithmetic stay locked to the colored shadow!

Interactive Lab 3: Rotate the Dot Product
u · v = +11.3
Slot-by-Slot Math (u · v)
4 × 2.83 + 0 × 2.83 = +11.3
Shadow & Alignment Dial (cos of angle)
cos(45°) = +0.71 · Shadow: +2.83
u = [4, 0]v = [2.83, 2.83]Thick colored shadow along the horizontal axis shows how much of v agrees with u.
45°
Pointing partly the same way (45°): because the angle is narrower than a 90° right angle, the alignment dial cos(45°) = +0.71 stays positive, giving a positive shadow (+2.83) and Dot Product (+11.3).

Notice 90°, which mathematicians call perpendicular (or orthogonal): whenever two non-zero arrows meet at a right angle, cos(90°) = 0, so their Dot Product equals exact 0.0. They share zero directional alignment, which is why neural networks and Self-Attention heads rely on dot products to test whether two patterns agree, oppose each other, or are completely unrelated.


Measuring vector length in ML: L1 vs. L2 vs. Unit Vectors

In math and machine learning, any ruler for measuring the size of a vector is called a norm. Depending on the task, you choose one of three simple rulers:

  1. Straight-Line Length (L2 norm, also called Euclidean length): The direct crow-flies distance from our map example. Square every coordinate, add them up, and take the square root. Because squaring turns negative steps positive, the arrow [3, -4] (3 blocks East, 4 blocks South) has straight-line length sqrt(3^2 + (-4)^2) = sqrt(9 + 16) = 5.0.
  2. City-Block Length (L1 norm, also called Manhattan length): Imagine a taxi that must follow the street grid instead of cutting diagonally through buildings. You add up the absolute value of each step (dropping minus signs, since walking 4 blocks South is still 4 blocks walked!). For [3, -4], the city-block distance is |3| + |-4| = 3 + 4 = 7.0.
  3. Unit Vector (shrinking any arrow to length 1.0): Sometimes you only care about which way an arrow points, not how long it is (for example, matching a short product review to a long article on the exact same topic). Dividing every coordinate of a vector by its L2 straight-line length keeps its exact same direction while setting its length to 1.0. For v = [3, 4] (whose L2 length is 5.0), dividing each slot by 5.0 gives the unit vector [0.6, 0.8]. Better still: when two arrows are both unit vectors of length 1.0, their Dot Product becomes 1 × 1 × cos(angle) = cos(angle), a pure direction score called Cosine Similarity.

Pick a vector below (be sure to test [3, -4]!) and click through all three rulers to see the straight diagonal, the city-block L-path, and the length-1 unit circle side by side.

Interactive Lab 4: Compare All Three Rulers
L2: 5.00L1: 7.00Unit: 1.00
Step 1, pick a vector:
L2 = 5.00v = [3, 4]
Step-by-Step Math on v = [3, 4]
sqrt(3^2 + 4^2) = sqrt(25) = 5.00
Everyday ML Use
Measuring distance: Finding straight-line closeness between data points or checking how far a prediction is from the true answer.
Straight-Line (L2) measures the direct crow-flies shortcut from [0, 0] to [3, 4]: sqrt(3^2 + 4^2) = sqrt(25) = 5.00 blocks.
See Algebraic & Geometric Dot Product Equivalence, Cauchy-Schwarz & Lp NormsThesis / Reference

1. Algebraic vs. Geometric Dot Product: For any u,v∈Rd\mathbf{u}, \mathbf{v} \in \mathbb{R}^d separated by angle θ\theta, the Law of Cosines proves exact equivalence between the coordinate sum and the projection shadow:

u⊤v=∑i=1duivi=∥u∥2 ∥v∥2cos⁡θ\mathbf{u}^\top \mathbf{v} = \sum_{i=1}^{d} u_i v_i = \|\mathbf{u}\|_2\,\|\mathbf{v}\|_2 \cos\theta

By the Cauchy-Schwarz inequality, ∣u⊤v∣≤∥u∥2∥v∥2|\mathbf{u}^\top \mathbf{v}| \le \|\mathbf{u}\|_2 \|\mathbf{v}\|_2, guaranteeing Cosine Similarity cos⁡θ=u⊤v∥u∥2∥v∥2∈[−1,+1]\cos\theta = \frac{\mathbf{u}^\top \mathbf{v}}{\|\mathbf{u}\|_2 \|\mathbf{v}\|_2} \in [-1, +1].

2. LpL_p Vector Norms: The general family ∥v∥p=(∑i=1d∣vi∣p)1/p\|\mathbf{v}\|_p = \left(\sum_{i=1}^{d} |v_i|^p\right)^{1/p} unifies Manhattan (p=1p=1), Euclidean (p=2p=2), and Chebyshev max-norm (p=∞p=\infty).

See Vector Norms & Dot Products in NumPyOptional Code
python
import numpy as np

u = np.array([4.0, 0.0])
v = np.array([2.83, 2.83])

dot = np.dot(u, v)                             # 11.32
l2_v = np.linalg.norm(v, ord=2)                # 4.00
l1_v = np.linalg.norm(v, ord=1)                # 5.66
cos_sim = dot / (np.linalg.norm(u) * l2_v)     # 0.71 (cos 45 deg)

Where can two arrows take you?

Now that you know how to add and scale two arrows, ask a geometric question: if you combine a · u + b · v for every possible pair of numbers a, b, can you reach every point on the 2D map, or do two look-alike arrows trap you on a skinny 1D rail?

Next up: Vector Spaces, Span & Basis.

✓ Self-Check

Quick Intuition Check

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

1

Two non-zero vectors u and v have a Dot Product of exactly 0.0. What does that tell you geometrically?

Pick an option first, or peek anytime
2

What happens to an arrow v = [3, 4] when you divide every coordinate by its Straight-Line (L2) length of 5.0?

Pick an option first, or peek anytime
3

Multiplying a vector by a negative scalar (such as -0.1 during Gradient Descent) shrinks or stretches the arrow and flips it 180 degrees in the opposite direction.

Pick an option first, or peek anytime
4

What are the Straight-Line (L2 / Euclidean) and City-Block (L1 / Manhattan) norms of the vector v = [3, -4]?

Pick an option first, or peek anytime
Quick Reference

Common Questions

What is a vector in machine learning?
In machine learning, a vector is simply an ordered list of numbers representing one data point, weight set, or word embedding (like [age, salary, clicks]), which we can visualize geometrically as an arrow from the origin to those coordinates.
What does the Dot Product measure intuitively?
The Dot Product measures how strongly two arrows point in the same direction (weighted by their lengths): positive when they agree (< 90 degrees), exact 0 when perpendicular/unrelated (90 degrees), and negative when opposing (> 90 degrees). It powers neurons (w·x) and Self-Attention (Q·K).
What is the difference between L1 Norm and L2 Norm?
The L2 Norm measures straight-line Euclidean length sqrt(sum v_i^2) and is used in Ridge/AdamW weight decay and K-Means. The L1 Norm sums absolute city-block steps sum(|v_i|) and drives Lasso feature selection to zero out noisy weights.
What does normalizing a vector to unit length mean?
Dividing every coordinate of a vector v by its L2 length ||v||_2 keeps its exact direction while setting its length to 1.0. The dot product of two unit vectors equals their exact Cosine Similarity.

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

https://seeingml.com/learn/vectors-dot-products/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@misc{irshad2026vectorsdotproducts,
  author       = {Irshad, Muhammad Aashir},
  title        = {Vectors, Norms & Dot Products: Interactive Visual Guide},
  howpublished = {SeeingML},
  year         = {2026},
  month        = {dec},
  url          = {https://seeingml.com/learn/vectors-dot-products/},
  note         = {Interactive visual guide}
}
APA

Irshad, M. A. (2026). Vectors, Norms & Dot Products: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/vectors-dot-products/