Linear Algebra for Machine Learning
Linear algebra crash course for ML — scalars, vectors, matrices, transpose, inverse, determinant, dot product, and matrix transformations explained with ML context. Includes the deeplearning.ai math learning path.
️Advance MultiVariant Linear Algebra
NVIDIA AI Infrastructure and Operations Fundamentals
Advanced Maths for Machine Learning and Data Science
Linear algebra is the language of space manipulation.
Machine learning is controlled geometric transformation.
Learning Path
deeplearning.ai Mathematics for ML and Data Science Specialization
1. Advanced Linear Algebra ∑
- Week 1: Systems of linear equations
- Week 2: Solving systems of linear equations
- Week 3: Vectors and Linear Transformations
- Week 4: Determinants and Eigenvectors
2. Calculus ∫
- Week 1: Derivatives and Optimization
- Week 2: Gradients and Gradient Descent
- Week 3: Optimization in Neural Networks and Newton's Method
3. Probability & Statistics 🎲
- Week 1: Introduction to Probability and Probability Distributions
- Week 2: Probability distributions with multiple variables
- Week 3: Sampling and Point estimation
- Week 4: Confidence Intervals and Hypothesis testing
Why Linear Algebra Matters in ML
Machine learning deals with multiple features, large datasets, efficient computation, and vectorized operations. Instead of writing nested loops, we use matrix operations to compute predictions and updates efficiently.
Think of ML as:
-
Data → points in high-dimensional space
-
Features → axes
-
Models → transformations
-
Training → adjusting geometry
-
Loss → distance between vectors
-
Optimization → walking downhill in space
-
Gradient descent becomes directional movement
-
Regularization becomes shrinking vector norms
-
Overfitting becomes high-dimensional distortion
-
RAG embeddings become spatial similarity
-
Attention becomes weighted projection
Mathematical Objects
A mathematical object is an abstract concept that can be assigned to a symbol and involved in formulas — numbers, expressions, shapes, functions, and sets.

Tensor
An algebraic object describing a multilinear relationship between sets of algebraic objects associated with a vector space.
Scalar ()
A single number — a 0-dimensional tensor.
Examples: , , ,
Matrices ()
A matrix is a 2D array of numbers.
In mathematics: — real-valued matrix, 3 rows, 4 columns.
In programming:
A = np.array([[85, 76, 66, 5],
[94, 75, 18, 28],
[68, 40, 71, 5]])
In theory:
- Uppercase letters (A, B, X) → Matrices
- Lowercase letters (x, y, z) → Vectors or scalars
Matrix Size
A ∈ ℝᵐˣⁿ → Matrix A has m rows and n columns
- Square matrix — same number of rows and columns ()
Element Notation
— element in the -th row and -th column.
- → Row 1, Column 1
- → Row 3, Column 2
Use in ML
The data matrix where each row is a training example and each column is a feature.
Vectors ()
A vector is a matrix with 1 column — a point in -dimensional space with direction and magnitude.
In math:
In programming: y = np.array([460, 232, 315, 178])
Dimension:
In ML, vectors represent:
- A data point
- A feature column (direction)
- A model weight vector (direction of best fit)
Element Indexing
— the -th element. Linear algebra uses 1-indexed notation by default.
Vector Norms
L1 norm:
L2 norm (Euclidean):
Transpose ()
Transpose swaps rows and columns.
If then
Used in: Normal Equation, gradient derivations.
Identity Matrix ()
The matrix equivalent of the number 1 — 1s on the diagonal, 0s everywhere else.
Inverse Matrix ()
Matrix inverse is like division. Only square matrices can have inverses.
Used in the Normal Equation:
Invertible vs Non-Invertible
| Type | Condition | |
|---|---|---|
| Invertible / non-singular | Has an inverse | Full rank — rows and columns linearly independent |
| Non-invertible / singular | No inverse | Rows or columns linearly dependent |
Common causes of non-invertibility:
- Redundant features (e.g., size in feet and meters — )
- More features than training examples () — use regularization
MATLAB/Octave:
pinv(A)— pseudo-inverse (works even if singular)inv(A)— standard inverse
Determinant ()
Tells us whether a matrix is invertible.
For a 2×2 matrix:
- → invertible
- → singular (no unique solution or infinitely many)
Regularization (Ridge Regression) adds a small value to the diagonal to ensure invertibility in practice.
Matrix as a Transformation
A matrix is a transformation of space. All ML models are compositions of transformations.
transforms vector into a new vector . Geometrically, a matrix can stretch, compress, rotate, reflect, shear, or project.
T : ℝ² → ℝ³ → T maps 2D vectors to 3D space
Matrix Addition / Subtraction
Addition is element-wise. Both matrices must have the same dimensions.
Matrix Multiplication ()
Given and :
Inner dimensions must match:
Properties:
- Not commutative:
- Associative:
Use in ML
Everything in deep learning is matrix multiplication:
- Inputs × Weights → activations
- Neural net forward pass:
- Backpropagation is matrix calculus
Vectorization
If is and is :
This computes predictions for all training examples in one operation — optimized for CPU/GPU hardware.
Linear regression hypothesis for all examples:
Dot Product ()
The dot product of two -dimensional vectors:
Produces a scalar.
Summary
| Concept | Role in ML |
|---|---|
| Vectors | Features, parameters, predictions |
| Matrices | Datasets, weight tensors, transformations |
| Transpose | Normal equation, gradient math |
| Inverse | Closed-form solutions |
| Matrix multiplication | Forward pass, vectorized predictions |
| Dot product | Similarity, attention scores |
| Determinant | Check invertibility |
