Stop 02 · Math FoundationsTopics · 1/9

Linear Algebra Essentials (Vectors, Matrices)

Part of the Data Science Roadmap

In short

Every dataset you load is secretly a matrix, and every row is a vector. Once you see that, things like model weights and recommendations stop looking like magic.

Vectors and matrices are the data structures underneath almost every ML model — understanding matrix multiplication and dot products makes concepts like weights and embeddings click much faster later.

The mascot holds a mess tray with rotis, a bowl of dal and rice beside a stack of plates.

Think of it like this

The hostel mess bill

Riya's order is a list: 4 rotis, 2 dal, 1 rice. The price list is another: 10, 30, 40. Multiply matching items and add them up, and you get her bill. Do that for every student at once and you've done matrix multiplication.

Watch it happen

Riya's bill as a dot product

4
0
2
1
1
2
·
3
10
4
30
5
40
6
=
7
?
8

1/5Left: Riya's order vector (rotis, dal, rice). Right: the price vector in rupees.

The big ideas

What you need to know

A vector is a list of numbers

One student's order, one house's features, one user's ratings. Each position means something specific.

A matrix is a stack of vectors

Rows are examples, columns are features. Your pandas DataFrame is basically a matrix with labels.

Dot product: multiply and add

It scores how much two vectors line up. Models use it to combine features with weights.

Matrix times vector does many at once

One multiplication gives the bill for every student. That's why NumPy and GPUs are so fast.

See it in code

Walk through the code

python
1import numpy as np2 3prices = np.array([10, 30, 40])      # roti, dal, rice4riya = np.array([4, 2, 1])5print(riya @ prices)                 # 1406 7orders = np.array([[4, 2, 1],8                   [6, 1, 2],9                   [2, 3, 0]])10print(orders @ prices)               # [140 170 110]

1/3Two vectors and their dot product: Riya's bill.

The @ operator does dot products and matrix multiplication. One line bills the whole mess.

Save yourself the pain

Common mistakes

Oops

Using * when you mean a dot product in NumPy.

Do this instead

* multiplies item by item. Use @ or np.dot for dot products and matrix multiplication.

Oops

Ignoring shapes until the code crashes.

Do this instead

Check .shape first. A (3, 3) matrix times a (3,) vector works; mismatched inner sizes don't.

Your mission

Bill your own canteen

~15 min

Quick check

A matrix has shape (100, 5) and a weight vector has shape (5,). What shape is their product?

Go deeper

  1. 1Practice multiplying small matrices by hand before relying on a library.
  2. 2Learn what a dot product represents geometrically (a measure of similarity/alignment).
  3. 3Connect this to a dataset: rows and columns as a matrix, and what operations on it mean.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge