Lesson 3.4 · Stage 03: The maths behind machine learning
Maths chapter 2: Vectors: lists of numbers
A vector is an ordered list of numbers. In ML, every data item becomes a vector.
A vector is an ordered list of numbers. In ML, every data item becomes a vector.
2.1 Two ways to see a vector
- As a list. A house with area 1200 sq ft, 3 bedrooms and age 10 years is the vector (1200, 3, 10). Each number is a component. This vector has 3 components, so it lives in 3 dimensions.
- As an arrow. The vector (3, 4) is an arrow from the origin (0, 0) that goes 3 steps right and 4 steps up.
We usually write vectors in bold, like a, or stand them up as a column.
2.2 Adding and subtracting
Add the matching components.
As arrows: walk along the first arrow, then the second. Subtraction works the same way: (5, 7) − (2, 3) = (3, 4).
2.3 Multiplying by a number (scaling)
Multiply every component by the number. The number is called a scalar, because it scales the arrow.
Multiplying by 2 doubles the length. Multiplying by −1 flips the arrow to point the opposite way.
2.4 Length of a vector
The length comes from Pythagoras’ theorem (class 7–8 geometry). For a = (3, 4):
The double bars ‖ ‖ mean “length”. It also works for more components: the length of (1, 2, 2) is √(1 + 4 + 4) = √9 = 3.
2.5 The dot product
The dot product of two vectors multiplies matching components and adds the results. The answer is a single number.
What it tells you:
- Large positive: the arrows point roughly the same way.
- Zero: they are at right angles (90°).
- Negative: they point in roughly opposite directions.
Worked example: a shopping bill. You buy 2 pens, 3 notebooks and 1 eraser. Prices are ₹10, ₹40 and ₹5. The bill is the dot product (2, 3, 1) · (10, 40, 5) = 20 + 120 + 5 = ₹145.
Why ML needs it: a simple model computes “weights · inputs”, which is exactly this shopping bill. Search engines and Oracle AI Vector Search compare meanings with dot products.
Try it
- Work out (2, −1) + (3, 5).
- Work out 3 × (1, −2, 4).
- Find the length of (6, 8).
- Find the dot product (2, 3) · (4, −1).
- Find (1, 2) · (2, −1). Chapter 4 explains what this answer means.