Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. 1 Linear Algebra

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🤯 Your stomach gets a new lining every 3–4 days.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🐙 Octopuses have three hearts and blue blood.
AI-Math

    AI-AgenticAI

    AI-DeepLearning

    AI-GenAI

    AI-Infrastructure

    AI-Machine-Learning

    AI-Math
    • ️Advance MultiVariant Linear Algebra

    • Linear Algebra for Machine Learning

    • MATLAB Crash Course

    • MATLAB Plotting & Visualization

    • AI-Math Index


    AWS

    Azure

    Hobbies

    kubernetes

    Management

    Programming

    Terraform

    Z_Appendix

    0-root

Cover Image for Linear Algebra for Machine Learning
AI-Math

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.

Linear Algebra
Machine Learning
Vectors
Matrices
Geometry
Scientific Computing
← Previous

️Advance MultiVariant Linear Algebra

Next →

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 (s∈Rs \in \mathbb{R}s∈R)

A single number — a 0-dimensional tensor.

Examples: 555, −3.14-3.14−3.14, π\piπ, eee


Matrices (A∈Rn×mA \in \mathbb{R}^{n \times m}A∈Rn×m)

A matrix is a 2D array of numbers.

A=[8576665947518286840715]A = \begin{bmatrix} 85 & 76 & 66 & 5 \\ 94 & 75 & 18 & 28 \\ 68 & 40 & 71 & 5 \end{bmatrix}A=​859468​767540​661871​5285​​

In mathematics: A∈R3×4A \in \mathbb{R}^{3 \times 4}A∈R3×4 — 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 (m=nm = nm=n)

Element Notation

AijA_{ij}Aij​ — element in the iii-th row and jjj-th column.

  • A11=85A_{11} = 85A11​=85 → Row 1, Column 1
  • A32=40A_{32} = 40A32​=40 → Row 3, Column 2

Use in ML

The data matrix X∈Rm×nX \in \mathbb{R}^{m \times n}X∈Rm×n where each row is a training example and each column is a feature.


Vectors (x⃗\vec{x}x)

A vector is a matrix with 1 column — a point in nnn-dimensional space with direction and magnitude.

x=[x1x2⋮xn]x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}x=​x1​x2​⋮xn​​​

In math: y∈R4y \in \mathbb{R}^4y∈R4

In programming: y = np.array([460, 232, 315, 178])

Dimension: n×1n \times 1n×1

In ML, vectors represent:

  • A data point
  • A feature column (direction)
  • A model weight vector (direction of best fit)

Element Indexing

yiy_iyi​ — the iii-th element. Linear algebra uses 1-indexed notation by default.

Vector Norms

L1 norm: ∥v∥1=∑∣vi∣\|v\|_1 = \sum |v_i|∥v∥1​=∑∣vi​∣

L2 norm (Euclidean): ∥v∥2=∑vi2\|v\|_2 = \sqrt{\sum v_i^2}∥v∥2​=∑vi2​​


Transpose (AT\mathbf{A}^TAT)

Transpose swaps rows and columns.

If A∈Rm×nA \in \mathbb{R}^{m \times n}A∈Rm×n then AT∈Rn×mA^T \in \mathbb{R}^{n \times m}AT∈Rn×m

(AT)ij=Aji(A^T)_{ij} = A_{ji}(AT)ij​=Aji​

A=[123456]⇒AT=[142536]A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} \quad \Rightarrow \quad A^T = \begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{bmatrix}A=[14​25​36​]⇒AT=​123​456​​

Used in: Normal Equation, gradient derivations.


Identity Matrix (III)

The matrix equivalent of the number 1 — 1s on the diagonal, 0s everywhere else.

I=[100010001]AI=IA=AI = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \qquad AI = IA = AI=​100​010​001​​AI=IA=A

Inverse Matrix (A−1A^{-1}A−1)

Matrix inverse is like division. Only square matrices can have inverses.

A−1A=AA−1=IA^{-1}A = AA^{-1} = IA−1A=AA−1=I

Used in the Normal Equation: θ=(XTX)−1XTy\theta = (X^T X)^{-1} X^T yθ=(XTX)−1XTy

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 — x2=kx1x_2 = kx_1x2​=kx1​)
  • More features than training examples (m≤nm \leq nm≤n) — use regularization

MATLAB/Octave:

  • pinv(A) — pseudo-inverse (works even if singular)
  • inv(A) — standard inverse

Determinant (det⁡(A)\det(A)det(A))

Tells us whether a matrix is invertible.

For a 2×2 matrix: det⁡(A)=ad−bc\det(A) = ad - bcdet(A)=ad−bc

  • det⁡(A)≠0\det(A) \neq 0det(A)=0 → invertible
  • det⁡(A)=0\det(A) = 0det(A)=0 → 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.

y=Axy = Axy=Ax

AAA transforms vector xxx into a new vector yyy. 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.

(A+B)ij=Aij+Bij(A + B)_{ij} = A_{ij} + B_{ij}(A+B)ij​=Aij​+Bij​ [1234]+[5678]=[681012]\begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix} + \begin{bmatrix}5 & 6 \\ 7 & 8\end{bmatrix} = \begin{bmatrix}6 & 8 \\ 10 & 12\end{bmatrix}[13​24​]+[57​68​]=[610​812​]

Matrix Multiplication (ABABAB)

Given A∈Rm×nA \in \mathbb{R}^{m \times n}A∈Rm×n and B∈Rn×pB \in \mathbb{R}^{n \times p}B∈Rn×p:

C=AB∈Rm×pCij=∑kAikBkjC = AB \in \mathbb{R}^{m \times p} \qquad C_{ij} = \sum_k A_{ik} B_{kj}C=AB∈Rm×pCij​=∑k​Aik​Bkj​

Inner dimensions must match: (m×n)(n×p)→(m×p)(m \times n)(n \times p) \rightarrow (m \times p)(m×n)(n×p)→(m×p)

Properties:

  • Not commutative: AB≠BAAB \ne BAAB=BA
  • Associative: (AB)C=A(BC)(AB)C = A(BC)(AB)C=A(BC)

Use in ML

Everything in deep learning is matrix multiplication:

  • Inputs × Weights → activations
  • Neural net forward pass: Z=WX+bZ = WX + bZ=WX+b
  • Backpropagation is matrix calculus

Vectorization

If XXX is m×nm \times nm×n and θ\thetaθ is n×1n \times 1n×1:

h=Xθ(m×1 predictions)h = X\theta \qquad (m \times 1 \text{ predictions})h=Xθ(m×1 predictions)

This computes predictions for all training examples in one operation — optimized for CPU/GPU hardware.

Linear regression hypothesis for all examples: h=Xθwhere hθ(x)=θTxh = X\theta \qquad \text{where } h_\theta(x) = \theta^T xh=Xθwhere hθ​(x)=θTx


Dot Product (a⋅ba \cdot ba⋅b)

The dot product of two nnn-dimensional vectors:

xTy=x1y1+x2y2+⋯+xnynx^T y = x_1 y_1 + x_2 y_2 + \dots + x_n y_nxTy=x1​y1​+x2​y2​+⋯+xn​yn​

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
Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Fri Feb 27 2026

Share This on

← Previous

️Advance MultiVariant Linear Algebra

Next →

NVIDIA AI Infrastructure and Operations Fundamentals

AI-Math/1-Linear-Algebra
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2026 All rights reserved.