Toggle to preview the lesson in Kannada
Module 14 — Maths Foundations
Linear algebra intuition

See what vectors, matrices, and dot products actually mean — geometrically and in code.

the problem

Open any ML paper. Within the first page you'll see vectors, matrices, dot products, and transformations. Without linear algebra intuition, these are just symbols. With it, you can see what a neural network is actually doing — moving points around in space. You don't need to be a mathematician. You need to see what these operations mean geometrically, then code them yourself.

concept 1 — vectors are points and directions

A vector is coordinates in space

A vector is just a list of numbers — but those numbers mean something. They're coordinates. In AI, vectors represent everything:

word → 768 numbers image → millions of pixels user → preference scores
x y 2 3 (0,0) (3, 2) v = [3, 2] Magnitude = √(3² + 2²) = √13 ≈ 3.61 points up and right from origin (0, 0)
concept 2 — matrices are transformations

A matrix moves points in space

A matrix transforms one vector into another. It can rotate, scale, stretch, or project. In AI, matrices are the model.

BEFORE A B M transformation matrix AFTER A' B'
Neural net weights
Matrices that transform input into output at each layer
Attention scores
Matrices that decide what parts of the input to focus on
Embeddings
Matrices that map words and tokens into vector space
concept 3 — dot product measures similarity

The dot product is how similarity is computed

The dot product of two vectors tells you how similar they are — and it powers search, RAG, and recommendations.

1 / 3
the code
a = [1, 2, 3]
3.7417
magnitude |a|
a · b
32
dot product
cosine similarity
0.9746
nearly identical direction
vector.py
class Vector:
    def __init__(self, components):
        self.components = list(components)
        self.dim = len(self.components)

    def __add__(self, other):
        return Vector([a + b for a, b in zip(self.components, other.components)])

    def __sub__(self, other):
        return Vector([a - b for a, b in zip(self.components, other.components)])

    def dot(self, other):
        return sum(a * b for a, b in zip(self.components, other.components))

    def magnitude(self):
        return sum(x**2 for x in self.components) ** 0.5

    def normalize(self):
        mag = self.magnitude()
        return Vector([x / mag for x in self.components])

    def cosine_similarity(self, other):
        return self.dot(other) / (self.magnitude() * other.magnitude())

    def __repr__(self):
        return f"Vector({self.components})"


a = Vector([1, 2, 3])
b = Vector([4, 5, 6])
print(f"a + b = {a + b}")
print(f"a · b = {a.dot(b)}")
print(f"|a|  = {a.magnitude():.4f}")
print(f"cosine similarity = {a.cosine_similarity(b):.4f}")
output
a + b =Vector([5, 7, 9])
a · b =32
|a| =3.7417
cosine similarity =0.9746
method reference
.dot(other)
Σ aᵢ×bᵢ — measures alignment. High = similar direction.
.magnitude()
√Σ xᵢ² — the length of the vector in space.
.normalize()
Divide by magnitude. Result has length = 1.
.cosine_similarity()
dot/(|a|×|b|). Range −1 to 1. Powers search and RAG.
💡 a · b = 32. Both vectors point in the same direction — large positive dot product. In a search engine, this means the query and document are highly relevant to each other.
in practice — how AI uses this
Real world: Spotify "Recommended Songs" Every song, user, and playlist is a vector. Dot product finds what you'll love next.
1
Your taste → a vector
Based on your listening history, Spotify encodes your taste as a high-dimensional vector. Lots of indie rock, late-night jazz, and fast BPM → specific coordinates in music space.
2
Every song is also a vector
Each of Spotify's 100M+ tracks is embedded into the same space using audio features, lyrics, and listening patterns. Similar songs cluster nearby.
3
Dot product finds your next song
Spotify computes the dot product (cosine similarity) between your taste vector and every song vector. The top matches become your "Discover Weekly" — computed fresh every Monday.
Cosine similarity: your taste vs candidate songs
Sufjan Stevens — "Death With Dignity"indie dream-pop · 68 BPM · night drive
0.97 ✓
Bon Iver — "Holocene"folk indie · 92 BPM · emotional
0.91 ✓
Travis Scott — "SICKO MODE"hip-hop · 155 BPM · high energy
0.11
Skrillex — "Bangarang"EDM · 110 BPM · aggressive
0.04
The same math powers Netflix recommendations, Google search, ChatGPT's RAG memory, and Amazon "customers also bought."
Unlock all 421 modules with full interactive lessons Enroll Now →