The Kirana Store Ledger
Ramesh runs a kirana store in a busy Bengaluru lane. He does not use any billing software — just a thin notebook. Next to each regular customer's name, he keeps a short list of numbers: how many kilograms of rice, how many kilograms of dal, how many litres of oil, and how many kilograms of sugar they usually buy in a month. For Mrs. Iyer, that line reads: 5, 2, 1, 3.
Ramesh has no idea he is doing linear algebra. But that ordered list of four numbers — quantities, written in a fixed sequence — is exactly what a mathematician calls a vector. And the moment he multiplies each quantity by its price and adds up the results to print Mrs. Iyer's bill, he performs the single most common calculation in modern artificial intelligence: the same one, repeated across enormous grids of numbers, that lets Netflix guess which show you will watch next, and lets Google decide which of billions of web pages to show you first.
What Exactly Is a Vector?
A vector is an ordered list of numbers, written as (a1, a2, ..., an). Each number is called a component, and the count of components is the vector's dimension. Mrs. Iyer's purchase list, q = (5, 2, 1, 3), is a 4-dimensional vector: quantities of rice, dal, oil, and sugar, in that fixed order.
Order matters enormously. If Ramesh ever swapped the second and third positions, "2 kg dal, 1 L oil" would silently become "1 kg dal, 2 L oil" — same four numbers, wrong meaning. Every vector used in AI carries this same rule: the position of a number, not only its value, is part of what it means.
A vector does not have to represent quantities. Ramesh also keeps a rate list — the price per unit of rice, dal, oil, and sugar, in the exact same order: p = (45, 120, 150, 42), in rupees. This is a second 4-dimensional vector, describing something completely different from the first, yet living in the same 4-dimensional space because it follows the same order of items. Keeping that order aligned across two vectors is what makes it possible to combine them meaningfully.
In two or three dimensions, a vector even has a picture: an arrow from the origin to a point, or simply the point itself, like (3, 4) on a graph. AI rarely stops at three dimensions — Mrs. Iyer's purchase vector already has four, and a single streaming user's taste profile can have hundreds of components. Nobody can sketch a 300-dimensional arrow, so beyond three dimensions everything is done using lists of numbers and arithmetic rules alone — rules that still agree exactly with the arrow-and-graph picture whenever there happen to be few enough dimensions to draw one.
Two Small Operations Before the Big One
Vectors support a few basic operations, and two are worth knowing before we go further.
- Vector addition: add matching components. If Mrs. Iyer buys
(5, 2, 1, 3)in week one and(3, 1, 0, 2)in week two, her fortnight total is(5+3, 2+1, 1+0, 3+2) = (8, 3, 1, 5). - Scalar multiplication: multiply every component by a single ordinary number, called a scalar to distinguish it from a vector. If a supplier doubles a standard order of
(5, 2, 1, 3), the new order is2 × (5, 2, 1, 3) = (10, 4, 2, 6).
Both operations work position by position, matching component to component. They are simple, but they establish the pattern behind the operation that matters most.
The Dot Product: Turning Two Lists Into One Number
Ramesh's real monthly task is not adding two quantity vectors — it is combining a quantity vector with a price vector to get a single rupee amount. This operation is called the dot product, and it is arguably the single most-used calculation in all of machine learning.
For two vectors of the same dimension, a = (a1, a2, ..., an) and b = (b1, b2, ..., bn), the dot product is defined as a · b = a1b1 + a2b2 + ... + anbn: multiply matching components, then add up all the results. The output is a single number, not a vector — the dot product always collapses two lists into one value.
Let's trace Mrs. Iyer's bill exactly this way, using q = (5, 2, 1, 3) and p = (45, 120, 150, 42).
q · p = (5 × 45) + (2 × 120) + (1 × 150) + (3 × 42)
= 225 + 240 + 150 + 126
= 741
Mrs. Iyer's bill is ₹741. Every step is only "multiply, then add." In code, the same logic looks like this:
quantities = [5, 2, 1, 3] # rice(kg), dal(kg), oil(L), sugar(kg)
prices = [45, 120, 150, 42] # price per unit, in rupees
total_bill = 0
for qty, price in zip(quantities, prices):
total_bill += qty * price
print(total_bill) # 741
Because this exact pattern shows up everywhere in AI, numerical libraries provide it as a ready-made function:
import numpy as np
quantities = np.array([5, 2, 1, 3])
prices = np.array([45, 120, 150, 42])
print(np.dot(quantities, prices)) # 741
Hold on to this one idea — multiply matching components, add the results — because everything from here on is a variation of it.
From Bills to Taste: Cosine Similarity and "Recommended for You"
Here is the same operation, aimed at a very different problem. Suppose two Netflix users each rated the same three films out of 5 stars — RRR, 3 Idiots, and Interstellar:
User A = (5, 4, 1) and User B = (4, 5, 2)
Both users clearly enjoy the first two films and dislike the third. Could a dot product alone measure how similar their taste is? Not quite — a dot product grows larger simply because ratings are larger, so a generous user who rates everything 5 stars would look artificially "similar" to almost anyone. What matters is direction, not size: two vectors pointing the same way in space represent similar taste, regardless of how long each vector is.
To remove the effect of size, divide the dot product by the magnitude (length) of each vector. A vector's magnitude extends the Pythagorean idea to more dimensions: |a| = √(a1² + a2² + ... + an²). Dividing the dot product by both magnitudes gives the cosine similarity:
cosine similarity = (a · b) / (|a| × |b|)
The result always falls between −1 and 1 (and, for non-negative ratings like these, between 0 and 1): a value near 1 means the two vectors point in almost the same direction — very similar taste — and a value near 0 means they have little in common. Let's trace it for User A and User B.
dot product: A · B = (5×4) + (4×5) + (1×2) = 20 + 20 + 2 = 42
magnitude A: |A| = √(5² + 4² + 1²) = √42 ≈ 6.481
magnitude B: |B| = √(4² + 5² + 2²) = √45 ≈ 6.708
cosine similarity = 42 / (6.481 × 6.708) = 42 / 43.474 ≈ 0.966
A similarity of roughly 0.97 out of a maximum of 1 says these two viewers have almost identical taste. This is the reasoning behind a "Because you and viewers like you watched..." row: find other users whose rating vectors point in nearly the same direction as yours, then recommend the films they rated highly that you have not seen yet. This general strategy — using what similar users liked, rather than analysing what a film is actually about — is called collaborative filtering.
import numpy as np
user_A = np.array([5, 4, 1]) # RRR, 3 Idiots, Interstellar
user_B = np.array([4, 5, 2])
dot_product = np.dot(user_A, user_B)
length_A = np.linalg.norm(user_A)
length_B = np.linalg.norm(user_B)
similarity = dot_product / (length_A * length_B)
print(round(similarity, 3)) # 0.966
Matrices: A Spreadsheet of Vectors
A real streaming platform is not comparing two users over three films — it is comparing tens of millions of users over tens of thousands of titles. Writing every user as a separate vector still works mathematically, but tracking thousands of separate vectors by hand is unmanageable. Instead, stack them into a grid: one row per user, one column per film, each cell holding a rating. This grid is called a matrix — literally a table of vectors, where every row is a vector and every column is a vector too.
A matrix with m rows and n columns is described as an m × n matrix. The tiny ratings table for User A and User B above would form a 2 × 3 matrix — two users as rows, three films as columns. Real recommendation matrices are enormous and mostly empty, since any one viewer has rated only a sliver of the catalogue; handling that emptiness efficiently is its own engineering problem, but the underlying mathematics does not change.
Ratings tables are only one example of a matrix hiding in plain sight. A black-and-white photograph is already one: one row per horizontal line of pixels, one column per vertical line, each entry a brightness value from 0 (black) to 255 (white). A colour photograph is simply three such matrices stacked together, one each for red, green, and blue intensity. Whether the numbers represent grocery quantities, star ratings, or pixel brightness, the moment data lines up in rows and columns, the same matrix operations apply.
Matrix Multiplication: Many Dot Products at Once
This is where the dot product scales up into a working recommendation engine. Real systems rarely predict ratings straight from a giant, mostly-empty ratings matrix. Instead, they search for a small number of hidden patterns — called latent factors — that explain the ratings already seen: perhaps one factor roughly tracks how much action a film has, and another tracks how much emotional drama it has. The algorithm is never told what these factors mean; it discovers whatever numbers best reproduce the known ratings. This technique, called matrix factorization, sat at the centre of the Netflix Prize — a public competition Netflix launched in 2006, offering $1,000,000 to any team that could improve its recommendation accuracy by at least 10%. It took nearly three years; the winning team, BellKor's Pragmatic Chaos, claimed the prize in 2009, and nearly every strong entry, including the winner, leaned heavily on matrix factorization.
To see the core arithmetic — not the discovery process, just what happens once the factors exist — say our two hidden factors are action intensity and emotional drama, each scored from 0 to 1. On these factors, RRR scores (0.9, 0.3), 3 Idiots scores (0.2, 0.8), and Interstellar scores (0.7, 0.6) — three rows of a movie matrix M. User A's preferences are (0.8, 0.5) and User B's are (0.3, 0.9) — two rows of a user matrix U.
To predict how much each user would enjoy each film, we multiply U by the transpose of M, written Mᵀ — the matrix flipped so its columns become rows. Flipping M turns its two columns into two rows: an action row, (0.9, 0.2, 0.7), and a drama row, (0.3, 0.8, 0.6), one value per film in the same order as before.
The rule for multiplying two matrices: to multiply an m × n matrix by an n × p matrix, the inner dimensions must match, and the result is an m × p matrix. Here U is 2 × 2 and Mᵀ is 2 × 3, so the result is 2 × 3 — two users, three predicted ratings each. Every entry of that result is nothing but a dot product: one row of U against one column of Mᵀ. Working through all six entries by hand:
User A, RRR: (0.8 × 0.9) + (0.5 × 0.3) = 0.72 + 0.15 = 0.87
User A, 3 Idiots: (0.8 × 0.2) + (0.5 × 0.8) = 0.16 + 0.40 = 0.56
User A, Interstellar: (0.8 × 0.7) + (0.5 × 0.6) = 0.56 + 0.30 = 0.86
User B, RRR: (0.3 × 0.9) + (0.9 × 0.3) = 0.27 + 0.27 = 0.54
User B, 3 Idiots: (0.3 × 0.2) + (0.9 × 0.8) = 0.06 + 0.72 = 0.78
User B, Interstellar: (0.3 × 0.7) + (0.9 × 0.6) = 0.21 + 0.54 = 0.75
Read down each user's row: User A's highest predicted score is RRR at 0.87 — the film the system recommends first. User B's highest is 3 Idiots at 0.78. Nothing here required knowing anything about the films beyond two hidden numbers per title; the entire recommendation fell out of six dot products, arranged in a grid. In code, the whole calculation collapses to one line:
import numpy as np
movies = np.array([
[0.9, 0.3], # RRR
[0.2, 0.8], # 3 Idiots
[0.7, 0.6], # Interstellar
])
users = np.array([
[0.8, 0.5], # User A
[0.3, 0.9], # User B
])
predicted_ratings = users @ movies.T
print(predicted_ratings)
# User A -> RRR 0.87, 3 Idiots 0.56, Interstellar 0.86
# User B -> RRR 0.54, 3 Idiots 0.78, Interstellar 0.75
That is matrix multiplication: not a new idea, but many dot products, computed together and arranged by row and column.
Same Math, Different Problem: How Google Ranks the Web
In 1998, two Stanford PhD students, Larry Page and Sergey Brin, faced a different problem: out of an already vast number of web pages, which ones actually matter? Their answer, an algorithm called PageRank, rested on a circular-sounding idea — a page is important if other important pages link to it — and linear algebra turns that circularity into a straightforward calculation.
Picture the web as pages connected by links, where each page splits a fixed amount of "importance" equally among every page it links to. Consider a tiny three-page web:
- Page X links to Page Y and Page Z
- Page Y links only to Page Z
- Page Z links only to Page X
Since X has two outgoing links, each gets half of X's importance; Y and Z each have a single outgoing link, so each gives all of its importance to the one page it links to. As a matrix where row i, column j holds how much of page j's importance flows into page i: the row feeding into X is (0, 0, 1) — everything arrives from Z; the row feeding into Y is (0.5, 0, 0) — half of X, nothing else; the row feeding into Z is (0.5, 1, 0) — half of X and all of Y.
Start by assuming every page is equally important: v0 = (1/3, 1/3, 1/3). Multiplying the matrix by this vector redistributes importance according to the links; doing it again redistributes it further, closer to a stable answer. This repeated matrix-vector multiplication is called power iteration. Tracing the first two rounds by hand:
Round 1:
into X: 0(1/3) + 0(1/3) + 1(1/3) = 1/3 ≈ 0.333
into Y: 0.5(1/3) + 0(1/3) + 0(1/3) = 1/6 ≈ 0.167
into Z: 0.5(1/3) + 1(1/3) + 0(1/3) = 1/2 = 0.500
v1 = (0.333, 0.167, 0.500)
Round 2:
into X: 0(0.333) + 0(0.167) + 1(0.500) = 0.500
into Y: 0.5(0.333) + 0(0.167) + 0(0.500) = 0.167
into Z: 0.5(0.333) + 1(0.167) + 0(0.500) = 0.333
v2 = (0.500, 0.167, 0.333)
Notice the total always stays 1 — importance is only ever redistributed, never created or destroyed. Keep repeating this step and the numbers stop swinging around, settling near a fixed point: X ≈ 0.4, Y ≈ 0.2, Z ≈ 0.4. That stable vector — the one further multiplication no longer changes — is the PageRank score of each page. Mathematicians call such a stable vector an eigenvector of the matrix, a term you will meet formally in a later grade; the only tool needed to compute one by hand — matrix-vector multiplication, repeated — is one you already have.
import numpy as np
M = np.array([
[0, 0, 1], # into X: from Z
[0.5, 0, 0], # into Y: from X
[0.5, 1, 0], # into Z: from X and Y
])
v = np.array([1/3, 1/3, 1/3])
for _ in range(30):
v = M @ v
print(np.round(v, 3)) # settles near [0.4 0.2 0.4]
The real PageRank algorithm adds one refinement: a small chance, governed by a constant called the damping factor (originally set around 0.85), that a reader ignores every link and jumps to a completely random page instead. This keeps the calculation well-behaved even when some pages have no outgoing links or form isolated clusters. Today, Google's actual search ranking blends in hundreds of additional signals beyond PageRank alone. But the founding idea, and the operation still sitting at its core, is exactly what you just traced by hand: a matrix, a vector, and repeated multiplication.
Back to the Notebook
Ramesh's notebook, the Netflix-style ratings grid, and Google's tiny three-page web all reduce to the same three ingredients:
- A vector — an ordered list of numbers representing something real: quantities, ratings, or link importance.
- A dot product — multiply matching components and add, collapsing two vectors into one meaningful number: a bill, a similarity score, or a flow of importance.
- A matrix — many vectors stacked into a grid, so that matrix multiplication can compute thousands of dot products in one organised step.
Nothing inside Netflix's recommendation row or Google's results page is conceptually beyond the arithmetic you just traced by hand. The scale is different — millions of users, billions of pages — but scale is handled by faster computers and cleverer engineering, not by different mathematics. It is also not the end of the story: every neural network layer you will meet in later chapters begins the same way, with an input vector multiplied by a weight matrix, long before anything resembling "intelligence" enters the picture. The next time a "Recommended for you" row loads in under a second, remember Mrs. Iyer's bill: somewhere underneath the interface, a very large version of the same multiply-and-add is running — just fast enough, and often enough, that nobody has to watch it happen.
Think About It
Think about this: How would you explain linear algebra foundations: the hidden math behind netflix and google to a friend who has never seen a computer? What real-world analogy would you use? Imagine you had to build a system using these concepts — what would be your first step? Try this: before moving on, write down three things you learned and one question you still have.
Practice Exercises
Now it is time to practice! Complete these challenges to solidify your understanding:
- Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
- Exercise 2: Find a real-world example where linear algebra foundations: the hidden math behind netflix and google is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
- Exercise 3: Create a mind-map connecting linear algebra foundations: the hidden math behind netflix and google to at least 3 other topics you have studied.
Key Takeaways — Summary and Recap
Let us recap what we covered: the core ideas behind linear algebra foundations: the hidden math behind netflix and google, how they connect to real-world applications, and why they matter for your journey in computer science. Remember these key points as you move forward. For competitive exam preparation (CBSE, JEE, BITSAT), focus on understanding the WHY behind each concept, not just the WHAT.