[New Book] Click to get The Beginner's Guide to Data Science!
Use the offer code 20offearlybird to get 20% off. Hurry, sale ends soon!

Linear Algebra Cheat Sheet for Machine Learning

All of the Linear Algebra Operations that You Need to Use
in NumPy for Machine Learning.

The Python numerical computation library called NumPy provides many linear algebra functions that may be useful as a machine learning practitioner.

In this tutorial, you will discover the key functions for working with vectors and matrices that you may find useful as a machine learning practitioner.

This is a cheat sheet and all examples are short and assume you are familiar with the operation being performed.

You may want to bookmark this page for future reference.

Kick-start your project with my new book Linear Algebra for Machine Learning, including step-by-step tutorials and the Python source code files for all examples.

Let’s get started.

Linear Algebra Cheat Sheet for Machine Learning

Linear Algebra Cheat Sheet for Machine Learning
Photo by Christoph Landers, some rights reserved.

Overview

This tutorial is divided into 7 parts; they are:

  1. Arrays
  2. Vectors
  3. Matrices
  4. Types of Matrices
  5. Matrix Operations
  6. Matrix Factorization
  7. Statistics

Need help with Linear Algebra for Machine Learning?

Take my free 7-day email crash course now (with sample code).

Click to sign-up and also get a free PDF Ebook version of the course.

1. Arrays

There are many ways to create NumPy arrays.

Array

Empty

Zeros

Ones

2. Vectors

A vector is a list or column of scalars.

Vector Addition

Vector Subtraction

Vector Multiplication

Vector Division

Vector Dot Product

Vector-Scalar Multiplication

Vector Norm

3. Matrices

A matrix is a two-dimensional array of scalars.

Matrix Addition

Matrix Subtraction

Matrix Multiplication (Hadamard Product)

Matrix Division

Matrix-Matrix Multiplication (Dot Product)

Matrix-Vector Multiplication (Dot Product)

Matrix-Scalar Multiplication

4. Types of Matrices

Different types of matrices are often used as elements in broader calculations.

Triangle Matrix

Diagonal Matrix

Identity Matrix

5. Matrix Operations

Matrix operations are often used as elements in broader calculations.

Matrix Transpose

Matrix Inversion

Matrix Trace

Matrix Determinant

Matrix Rank

6. Matrix Factorization

Matrix factorization, or matrix decomposition, breaks a matrix down into its constituent parts to make other operations simpler and more numerically stable.

LU Decomposition

QR Decomposition

Eigendecomposition

Singular-Value Decomposition

7. Statistics

Statistics summarize the contents of vectors or matrices and are often used as components in broader operations.

Mean

Variance

Standard Deviation

Covariance Matrix

Linear Least Squares

Further Reading

This section provides more resources on the topic if you are looking to go deeper.

NumPy API

Other Cheat Sheets

Summary

In this tutorial, you discovered the key functions for linear algebra that you may find useful as a machine learning practitioner.

Are there other key linear algebra functions that you use or know of?
Let me know in the comments below.

Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.

Get a Handle on Linear Algebra for Machine Learning!

Linear Algebra for Machine Learning

Develop a working understand of linear algebra

...by writing lines of code in python

Discover how in my new Ebook:
Linear Algebra for Machine Learning

It provides self-study tutorials on topics like:
Vector Norms, Matrix Multiplication, Tensors, Eigendecomposition, SVD, PCA and much more...

Finally Understand the Mathematics of Data

Skip the Academics. Just Results.

See What's Inside

13 Responses to Linear Algebra Cheat Sheet for Machine Learning

  1. Avatar
    Azhaar February 23, 2018 at 5:22 am #

    Very helpful! thanks for compiling and sharing this cheat sheet.

  2. Avatar
    Matthew February 23, 2018 at 1:09 pm #

    Thanks Jason, it is very helpful. I like it!

    • Avatar
      Jason Brownlee February 24, 2018 at 9:08 am #

      Thanks Matthew!

    • Avatar
      Gerardo October 28, 2021 at 12:17 pm #

      Thank you for sharing! Good info inside

  3. Avatar
    Balaji Venkateswaran February 23, 2018 at 4:08 pm #

    Thanks for this quick cheat sheet. Very useful one!

  4. Avatar
    Akhtar February 23, 2018 at 5:13 pm #

    Thanks Jason, this is super helpful.

  5. Avatar
    Damian May 4, 2018 at 10:32 pm #

    Hello.
    Thanks for this summary.
    A small remark:
    Matrix-Scalar Multiplication doesn’t work exclusively like that (at least in python 3.6)
    you are able to use either A*scalar(k) or np.dot (k).
    And it makes more sense to respect original math notations and not to abuse the function by using a scalar with it.

  6. Avatar
    Donald Lacombe October 26, 2021 at 1:41 am #

    One can save a few keystrokes by using the @ symbol for the dot product:

    A@b

    • Avatar
      Adrian Tam October 27, 2021 at 2:27 am #

      Yes, you’re right. But only available in Python 3.5 and afterwards.

Leave a Reply