Matrix

Matrix

Gajendra
7 min readAug 25, 2022

Before we try to understand Matrix we should get familiar with Vectors as Matrix is simply multiple vectors put together.

The article only focuses on the the concepts required for the data science and not every concepts of matrices.

Matrix

A Matrix represents a set of vectors put together. Each column of a matrix represents a vector and each row represents the elements of the vector,

Matrix

Representation

A Matrix is represented by a capital letter, A — Z. The elements in the matrix is represented by lowercase letters, a — z, with number of rows followed by number of columns.

Matrix Representation
Matrix Representation

Types of Matrix

Column Matrix

This is simply a matrix with just 1 column.

Column Matrix

Row Matrix

This is simply a matrix with just 1 row.

Row Matrix

Null or Zero Matrix

All the elements of the matrix are equal to 0.

Null or Zero Matrix

Square Matrix

A matrix with equal number of rows and columns.

Square Matrix

Diagonal Matrix

All elements other than diagonal are equal to 0.

Diagonal Matrix

A diagonal matrix with all the values in diagonal equal to 1 is called Unit or Identity matrix.

Unit or Identity Matrix

There are few other types of matrices such as scalar matrix, upper triangular matrix, lower triangular matrix, symmetric matrix, and antisymmetric matrix but we do not need to focus too much on those.

Operations

Addition

We can only add 2 or more matrices if the number of rows and columns of both the matrices are the same.

Matrix Addition

Subtraction

We can only subtract 2 or more matrices if the number of rows and columns of both the matrices are the same.

Matrix Subtraction

Multiplication

Scalar Multiplication

Every element of a matrix is multiplied by the scalar value.

Scalar Multiplication

Properties

Here are some of the properties of scalar multiplication.

Properties of Scalar Multiplication

Matrices Multiplication

The multiplication is only possible when the number of columns in the first matrix and rows in the second matrix are equal.

Each element of a row from first matrix is multiplied by the each element of the column of the second matrix.

Matrices Multiplication
Matrices Multiplication

This is also known as Dot Product for matrices.

Properties

Here are some of the properties of matrices multiplication.

Properties of Matrices Multiplication

Transpose

We replace the rows of a matrix to the columns and columns to the rows. Interchanging of rows and columns is known as the transpose of matrices.

Transpose

Properties

Here are some of the properties of matrices transpose.

Properties of Matrix Transpose

Determinant

Determinant gives us the scalar value and it can only be calculated for a square matrix.

Determinant 2x2 Matrix
Determinant 3x3 Matrix

Note the sequence of +,-,+… while calculating the determinant.

Inverse

The inverse of a square matrix, sometimes called a reciprocal matrix, is a matrix such that.

Invers Matrix

To calculate the inverse of a matrix we need to understand the Minor, Cofactor and Adjoin of matrices. For the purpose of data science we don’t need to go into such details.

Hadamard Product

Hadamard product or element-wise product takes two matrices of the same dimensions and produces another matrix of the same dimension.

Hadamard Product

Echelon Form

A matrix is in Echelon form if it satisfies the below properties.

  1. Any rows, if any, of all zeroes is the last row.
1

2. Each leading entry of a row is in a column to the right of the leading entry in the row above it.

2

3. All entries in a column below a leading entry are zero.

3

Row (Column) Echelon Form

Apart from the properties above there is one additional important property here i.e. the first non-zero element in each row (column), called the leading entry, is 1.

Row (Column) Echelon Form

Reduced Row (column) Echelon Form

Apart from the properties above here is one additional important property here i.e. the leading entry in each row (column) is the only non-zero entry in its column (row).

Reduced Row (column) Echelon Form

Rank

Rank is one of the important concept in Matrix. It helps us identify linearity in the matrix. The Rank tells us the maximum number of linearly independent columns or rows in a matrix.

To calculate the rank we first check if the determinant of the matrix is 0 or not.

  • If |A| != 0, then the rank of the matrix is the number of rows of the matrix.
  • If |A| = 0, we convert the matrix into its echelon form by reducing the rows until it cannot be further.

Example

|A| != 0

Rank for |A| != 0

|A| = 0

|A| = 0

Now we apply elementary transformations (row reduce)

Transformation

We get

Transformed Matrix

Again,

Transformation

We get

Transformed Matrix

We cannot further reduce the matrix so we stop here. The number of non — zero rows is 2. So the rank of the matrix is 2.

Linear Independence

Set of vectors are independent if they do not lie on the same plane. If the vectors lie on the same plane they are dependent.

Liner Independent and Dependent

A set of vectors {v1, v2, …, vk} is linearly independent if the vector equation

Vector Equation

has only the trivial solution

Trivial Solution

The set {v1, v2, …, vk} is linearly dependent otherwise.

Example

Linear Dependence

Given Vectors

Vectors

Vector Equation

Vector Equation

We solve this by forming a matrix and row reducing

Row Reduce

We get,

Equations

And finally,

Equations

So there exist non-trivial solutions. For instance, taking z=1 (!= 0) gives this equation of linear dependence.

Linear Dependence Equation

So, there is a solution other than the trivial solution. We conclude that the set is Linearly Dependent.

Linear Independence

Given Vectors

Vectors

Vector Equation

Vector Equation

We solve this by forming a matrix and row reducing

Row Reduce

We get,

Equations

And finally,

Equations

So, the only solution is the trivial solution. We conclude that the set is Linearly Independent.

I hope this article provides you with a good understanding of some important concepts of Matrices.

If you have any questions or if you find anything misrepresented please let me know.

Thanks!

--

--

Gajendra

| AWS MLS, SAA, CLF | MIT - ADSP | Software Engineer | Data Scientist | Machine Learning | Artificial Intelligence | Hobby Blogger |