Every machine learning model — from a simple spam filter to GPT-style language models — does the same thing under the hood: it turns real-world things into numbers, arranges those numbers into vectors and matrices, and multiplies them.
Linear algebra for machine learning isn't an academic prerequisite you can skip. It's the actual mechanism models use to represent data and make predictions. If you understand vectors, matrices, matrix multiplication, and the dot product, you understand what's literally happening inside a model when it makes a decision.
This guide covers the four concepts you'll run into in every ML codebase, with the real computation behind each one.
Vectors: How Machines Represent "Things"
A vector is a list of numbers. In machine learning, it's how you turn anything — a house, a customer, a sentence, a pixel grid — into a form a model can compute with. Each number in the vector is a feature.
Take a house with 1,800 square feet, 3 bedrooms, 12 years old, and 6.5 km from the city center. As a feature vector, that's:
x = [1800, 3, 12, 6.5]
That's it — that's how a house-price model "sees" a house. It has no concept of walls or windows, only this list of numbers.

Left: raw attributes of a house become a feature vector x. Right: once data is a vector, it becomes a point (and a direction) in space — houses with similar features point in similar directions, which is exactly how models group and compare things.
This same idea scales to everything in ML:
- Images → a vector of pixel intensities (a 28×28 grayscale image is a 784-number vector).
- Words → embedding vectors like Word2Vec or GPT token embeddings, typically 300–12,000+ numbers long, where similar meanings produce similar vectors.
- Users on Netflix or Spotify → a vector of genre/artist preference scores used for recommendations.
A model doesn't "understand" a cat photo or a customer. It understands a vector, and everything it does — classifying, predicting, generating — is arithmetic on that vector.
Matrices: How Machines Represent Datasets and Layers
A matrix is a grid of numbers — rows and columns. In ML, matrices show up in two critical places:
1. A matrix represents a whole dataset. Stack multiple feature vectors (one per row) and you get a matrix, where each row is one example and each column is one feature.

A dataset of 4 houses × 4 features is literally a 4×4 matrix. When you call model.fit(X, y) in scikit-learn, X is exactly this — a matrix where rows are examples and columns are features.
2. A matrix represents the learned "knowledge" of a model. Every layer in a neural network has a weight matrix — the numbers the model adjusts during training. A model with a 512-unit layer feeding into a 256-unit layer stores that connection as a 512×256 matrix. GPT-3's 175 billion parameters are, structurally, a large collection of matrices.
This is why GPU acceleration exists: GPUs are built to do matrix arithmetic in parallel, which is why training and running deep learning models on a GPU is 10–100x faster than on a CPU.
Matrix Multiplication: The Core Operation of a Neural Network
Matrix multiplication is how a model transforms input data into a prediction. When you multiply an input vector by a weight matrix, you get an output vector — this single operation is what a "layer" in a neural network actually does.
For a matrix A (size m×n) and matrix B (size n×p), the result A×B is an m×p matrix, where each entry is a dot product of a row from A and a column from B. The inner dimensions must match (n in both) — this is why you'll see shape mismatch errors constantly in PyTorch and TensorFlow; it's the model literally refusing to multiply matrices that don't line up.

A 3-number input passes through a weight matrix to produce a 2-number output. Each output value is the dot product of one row of weights with the input. Stack dozens of these layers and you have a deep neural network — it's the same multiplication, repeated.
Concretely: when you run an image through a convolutional neural network, or a sentence through a transformer, the data is repeatedly reshaped by matrix multiplication at every layer, with each multiplication followed by a non-linear function (like ReLU) so the network can learn more than straight lines. Remove the multiplications and there's no network — just a static list of numbers.
Dot Product: How Models Measure Similarity
The dot product multiplies two vectors element-by-element and sums the results:
[a1, a2, a3] · [b1, b2, b3] = a1*b1 + a2*b2 + a3*b3
Geometrically, the dot product is high when two vectors point in a similar direction, and low (or negative) when they point in different directions. This single fact is the basis for similarity search, recommendations, and attention mechanisms across ML.

Movies (or products, or songs) become vectors of genre/attribute scores. The dot product between a user's taste vector and each movie vector ranks them by similarity — this is the arithmetic behind "Because you watched..." recommendations.
Real systems built on the dot product:
- Recommendation engines (Netflix, Spotify, Amazon) rank items by the dot product (or cosine similarity, a normalized dot product) between a user vector and item vectors.
- Semantic search and RAG systems compare a query embedding against a database of document embeddings using dot products to find the closest matches.
- Transformer attention (the mechanism behind GPT and BERT) computes attention scores as the dot product between "query" and "key" vectors, deciding which words in a sentence a model should focus on for each prediction.
Putting It Together
A single forward pass through a neural network is: take an input vector, multiply it by a weight matrix (a sequence of dot products), apply a non-linear function, and repeat through every layer until you reach an output — a predicted price, a classification, or the next word in a sentence.
That's the whole story. Deep learning frameworks like PyTorch and TensorFlow are, at their core, highly optimized systems for doing exactly this kind of linear algebra at massive scale. Once these four operations click, reading model architectures, debugging shape errors, and understanding why a model behaves the way it does all get significantly easier.