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.

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.

Download Your FREE Mini-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.

Click to learn more.


10 Responses to Linear Algebra Cheat Sheet for Machine Learning

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

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

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

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

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

    Thanks for this quick cheat sheet. Very useful one!

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

    Thanks Jason, this is super helpful.

  5. 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.

Leave a Reply