# A Gentle Introduction to Linear Algebra

Last Updated on

### What is Linear Algebra?

Linear algebra is a field of mathematics that is universally agreed to be a prerequisite to a deeper understanding of machine learning.

Although linear algebra is a large field with many esoteric theories and findings, the nuts and bolts tools and notations taken from the field are practical for machine learning practitioners. With a solid foundation of what linear algebra is, it is possible to focus on just the good or relevant parts.

In this tutorial, you will discover what exactly linear algebra is from a machine learning perspective.

After completing this tutorial, you will know:

• Linear algebra is the mathematics of data.
• Linear algebra has had a marked impact on the field of statistics.
• Linear algebra underlies many practical mathematical tools, such as Fourier series and computer graphics.

Discover vectors, matrices, tensors, matrix types, matrix factorization, PCA, SVD and much more in my new book, with 19 step-by-step tutorials and full source code.

Let’s get started. A Gentle Introduction to Linear Algebra
Photo by Steve Corey, some rights reserved.

## Tutorial Overview

This tutorial is divided into 4 parts; they are:

1. Linear Algebra
2. Numerical Linear Algebra
3. Linear Algebra and Statistics
4. Applications of Linear Algebra

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

## Linear Algebra

Linear algebra is a branch of mathematics, but the truth of it is that linear algebra is the mathematics of data. Matrices and vectors are the language of data.

Linear algebra is about linear combinations. That is, using arithmetic on columns of numbers called vectors and arrays of numbers called matrices, to create new columns and arrays of numbers. Linear algebra is the study of lines and planes, vector spaces and mappings that are required for linear transforms.

It is a relatively young field of study, having initially been formalized in the 1800s in order to find unknowns in systems of linear equations. A linear equation is just a series of terms and mathematical operations where some terms are unknown; for example:

Equations like this are linear in that they describe a line on a two-dimensional graph. The line comes from plugging in different values into the unknown x to find out what the equation or model does to the value of y.

We can line up a system of equations with the same form with two or more unknowns; for example:

The column of y values can be taken as a column vector of outputs from the equation. The two columns of floating-point values are the data columns, say a1 and a2, and can be taken as a matrix A. The two unknown values x1 and x2 can be taken as the coefficients of the equation and together form a vector of unknowns b to be solved. We can write this compactly using linear algebra notation as:

Problems of this form are generally challenging to solve because there are more unknowns (here we have 2) than there are equations to solve (here we have 3). Further, there is often no single line that can satisfy all of the equations without error. Systems describing problems we are often interested in (such as a linear regression) can have an infinite number of solutions.

This gives a small taste of the very core of linear algebra that interests us as machine learning practitioners. Much of the rest of the operations are about making this problem and problems like it easier to understand and solve.

## Numerical Linear Algebra

The application of linear algebra in computers is often called numerical linear algebra.

“numerical” linear algebra is really applied linear algebra.

— Page ix, Numerical Linear Algebra, 1997.

It is more than just the implementation of linear algebra operations in code libraries; it also includes the careful handling of the problems of applied mathematics, such as working with the limited floating point precision of digital computers.

Computers are good at performing linear algebra calculations, and much of the dependence on Graphical Processing Units (GPUs) by modern machine learning methods such as deep learning is because of their ability to compute linear algebra operations fast.

Efficient implementations of vector and matrix operations were originally implemented in the FORTRAN programming language in the 1970s and 1980s and a lot of code, or code ported from those implementations, underlies much of the linear algebra performed using modern programming languages, such as Python.

Three popular open source numerical linear algebra libraries that implement these functions are:

• Linear Algebra Package, or LAPACK.
• Basic Linear Algebra Subprograms, or BLAS (a standard for linear algebra libraries).
• Automatically Tuned Linear Algebra Software, or ATLAS.

Often, when you are calculating linear algebra operations directly or indirectly via higher-order algorithms, your code is very likely dipping down to use one of these, or similar linear algebra libraries. The name of one of more of these underlying libraries may be familiar to you if you have installed or compiled any of Python’s numerical libraries such as SciPy and NumPy.

## Linear Algebra and Statistics

Linear algebra is a valuable tool in other branches of mathematics, especially statistics.

Usually students studying statistics are expected to have seen at least one semester of linear algebra (or applied algebra) at the undergraduate level.

— Page xv, Linear Algebra and Matrix Analysis for Statistics, 2014.

The impact of linear algebra is important to consider, given the foundational relationship both fields have with the field of applied machine learning.

Some clear fingerprints of linear algebra on statistics and statistical methods include:

• Use of vector and matrix notation, especially with multivariate statistics.
• Solutions to least squares and weighted least squares, such as for linear regression.
• Estimates of mean and variance of data matrices.
• The covariance matrix that plays a key role in multinomial Gaussian distributions.
• Principal component analysis for data reduction that draws many of these elements together.

As you can see, modern statistics and data analysis, at least as far as the interests of a machine learning practitioner are concerned, depend on the understanding and tools of linear algebra.

## Applications of Linear Algebra

As linear algebra is the mathematics of data, the tools of linear algebra are used in many domains.

In his classical book on the topic titled “Introduction to Linear Algebra“, Gilbert Strang provides a chapter dedicated to the applications of linear algebra. In it, he demonstrates specific mathematical tools rooted in linear algebra. Briefly they are:

• Matrices in Engineering, such as a line of springs.
• Graphs and Networks, such as analyzing networks.
• Markov Matrices, Population, and Economics, such as population growth.
• Linear Programming, the simplex optimization method.
• Fourier Series: Linear Algebra for functions, used widely in signal processing.
• Linear Algebra for statistics and probability, such as least squares for regression.
• Computer Graphics, such as the various translation, rescaling and rotation of images.

Another interesting application of linear algebra is that it is the type of mathematics used by Albert Einstein in parts of his theory of relativity. Specifically tensors and tensor calculus. He also introduced a new type of linear algebra notation to physics called Einstein notation, or the Einstein summation convention.

## Linear Algebra Tutorials

Are you looking for some help to get started with linear algebra, then take a look at some of these tutorials:

## Extensions

This section lists some ideas for extending the tutorial that you may wish to explore.

• Search books and the web for 5 quotations defining the field of linear algebra.
• Research and list 5 more applications or uses of linear algebra in the field probability and statistics.
• List and write short definitions for 10 terms used in the description of linear algebra.

If you explore any of these extensions, I’d love to know.

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

## Summary

In this tutorial, you discovered a gentle introduction to linear algebra from a machine learning perspective.

Specifically, you learned:

• Linear algebra is the mathematics of data.
• Linear algebra has had a marked impact on the field of statistics.
• Linear algebra underlies many practical mathematical tools, such as Fourier series and computer graphics.

Do you have any questions?

## Get a Handle on 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...

### 20 Responses to A Gentle Introduction to Linear Algebra

1. Dan January 26, 2018 at 7:12 pm #

Thanks Jason for the ongoing contributions you make – this site is a wealth of resources for me to learn to apply ML in my academic research from scratch

• Jason Brownlee January 27, 2018 at 5:56 am #

You’re welcome Dan.

2. David January 29, 2018 at 4:33 am #

Jason,

Thank you for the linear algebra introduction, I found it very useful.

As part of your Extensions exercise, I wrote a blog about my own linear algebra exploration https://agentcurry.com/2018/01/linear-algebra-exploration

I only recently found your website and find it to be a great resource for machine learning. Thank you for your contributions.

~David

• Jason Brownlee January 29, 2018 at 8:18 am #

Thanks.

3. SiVa January 30, 2018 at 4:32 pm #

Hey brownlee,

Thanks for the linear algebra introduction.

• Jason Brownlee January 31, 2018 at 9:37 am #

You’re welcome.

4. Sameer Madamaiah July 11, 2018 at 2:30 pm #

Thank you so much for this information

• Jason Brownlee July 11, 2018 at 2:57 pm #

5. Amit Mukherjee July 14, 2018 at 2:12 am #

I am learning linear algebra to implement machine learning solutions for solving business problems.

Thanks Jason for the systematic organization of the course.

• Jason Brownlee July 14, 2018 at 6:19 am #

You’re welcome.

6. alvhin August 6, 2018 at 11:51 pm #

sir can you help about my topic mastery level in linear algebra thesis tnx

7. Buba March 14, 2019 at 5:35 pm #

Problems of this form are generally challenging to solve because there are more unknowns (here we have 2) than there are equations to solve (here we have 3).

But 2 is less than 3.

• Jason Brownlee March 15, 2019 at 5:26 am #

Yes, that makes 2 x 3 unknowns across the 3 equations. My point was that the unknowns scale with the number of equations.

8. Saurabh April 22, 2019 at 5:57 am #

Hello Sir,

I am an Arts student, with a very little exposure to Maths, At the same time I am interseted in learning Analytics and Automation.

As a beginner please can you suggest me how should I begin. I order to learn and understand Analytics and Automation.

• Jason Brownlee April 22, 2019 at 6:26 am #

I would recommend diving into the specific area that interests you.

9. Harshdeep Prajapati June 25, 2019 at 3:19 pm #

Hi sir, I’m really want to be a part of data revolution that will change the world. I’m really want to learn data analytics and BIG DATA that involves in a business decisions process. But the problem is that, I hate maths since my school days. But I think now I’ve to learn it. At the time commenting this, I’ve Zero knowledge of maths. However, I’ve been working in web development in python Django since mid 2016. And Knowledge of AWS. Technology wise I’ve sufficient knowledge to dive into Data Analyst and BIG DATA field. But, Maths Scares Me. Please Help.

10. Alaa September 5, 2019 at 3:27 am #

Thank you so much your books help me to learn a lot about machine learning and other subjects

• Jason Brownlee September 5, 2019 at 6:58 am #