Lessons › Chapter 2: Math toolkit
Vectors
A single number, like a temperature or a price, is called a scalar. Picture it as one bar.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Customers as lists of numbers
To feed customers into a model, Leo turns each one into a list of numbers: income, age, balance.
A scalar is one number
A single number, like a temperature or a price, is called a scalar. Picture it as one bar.
A vector is a list of numbers
Line several numbers up and you have a vector. A house with size 3, 1 bathroom and 2 floors becomes [3, 1, 2]. ML turns every example into a vector like this.
A vector is also an arrow
Two numbers can be drawn as an arrow from the origin: go 2 along x, then 1 along y. The arrow has a direction and a length.
Adding vectors: tip to tail
To add b, start it where a ends. The arrow from the origin to the final tip is a + b = [3, 4]. In numbers, just add matching components.
Scaling stretches the arrow
Multiply a vector by a number and every component scales. 2 × a = [4, 2] points the same way, twice as long. A negative number flips it around.
The length of a vector
By Pythagoras, the length (or norm) of [2, 1] is √(2² + 1²) ≈ 2.24. ML uses lengths and distances constantly: how far apart are two examples?
In real life: songs as lists of numbers
Music apps can describe each song with a handful of numbers, like tempo, energy and mood. That turns every song into a vector. “Find songs like this one” then becomes “find arrows that point nearly the same way”.
Quick check: A house with size 120, 3 rooms and 10 years old becomes…
- The vector [120, 3, 10] (correct)
- The single number 133
- A 3 × 3 matrix
Each feature becomes one component of the example’s feature vector.
Pseudocode
# a vector is just a list of numbers v = [3, 1, 2] a = [2, 1] b = [1, 3] a + b # [2+1, 1+3] = [3, 4] 2 × a # [4, 2]: every number doubled length(a) # √(2² + 1²) ≈ 2.24
Key terms
- scalar
- A single number.
- vector
- A list of numbers. It can also be drawn as an arrow.
- norm
- The length of a vector.