The next topic to learn is Matrices, to set up a strong foundation for Data Science. We have learned Linear Algebra, Coordinate Geometry, and Planes in previous articles.

## Introduction to Matrices

A **Matrix **(plural: matrices) is an arrangement in a rectangular, ordered array of numbers. The existence of n-dimensional planes in our coordinate space gave rise to the invention of the matrix.

The numbers in the array are called the entities or elements of the matrix. The horizontal array of elements in the matrix is called **rows**, and the vertical array of elements is called the **columns**. If a matrix has m rows and n columns, it is known as the matrix of order m x n, and m and n are called its dimensions.

## Matrices Notations

In a matrix, an array of numbers is arranged in square brackets, as shown below:

The above matrix has 4 rows and 3 columns. So, here m = 4 and n = 3, a 4×3 matrix.

Matrix A is generally represented by symbol A:= [a_{ij}]_{mxn}

The values in the matrix are called elements or entries of a matrix. Let’s take the value of a matrix ‘A’ that lies in the row number i and column number j is called the i,j entry of A. This is written as A[i,j] or a_{i,j, }for all 1 ≤ i ≤ m and 1 ≤ j ≤ n.

The element A[2,3] or a_{2,3} is 8.

## Types of Matrices

Depending upon the order and elements, matrices are classified as explained below:

### Column Matrix

A column matrix is a matrix with a single column of m elements. The column matrix is an m × 1 matrix. It is also called a column vector.

This is a column vector with dimension 3 x1

### Row Matrix

A Row matrix is a matrix with a single row of n elements. The column matrix is a 1 × n matrix. It is also called a row vector.

This is a row vector with dimension 1 x 3

### Rectangular Matrix

A matrix with an unequal number of rows and columns, i.e., m is not equal to n.

This is a rectangular matrix of dimensions 3×2

### Square Matrix

A square matrix contains an equal number of (m = n) rows and columns. The expression for it is m × m.

This is a square matrix with dimension 3 x 3

### Diagonal Matrix

A matrix with non-zero elements in its diagonal part runs from upper left to lower right, or vice versa, and all other elements are zero. A diagonal matrix must be a square matrix.

When the element where i = j is non-zero and all other elements are zero, then it is a diagonal matrix

### Scalar Matrix

The scalar matrix is a square matrix, which has all its diagonal elements equal and all the other elements as zero.

It is a variant of the diagonal matrix.

### Identity Matrix

A square matrix has all its principal diagonal elements as one and all other non-diagonal elements as zeros.

It is also a variant of the diagonal matrix.

### Zero Matrix

A matrix whose all entries are zero. It is also called a null matrix.

It is a 3×3 zero matrix.

## Operations on Matrices

Various operations that can be performed on matrices are addition, subtraction, multiplication, and transpose. Let’s discuss them in detail.

### Addition

If two matrices are of the same dimensions, say m x n, then they can be added, and the output matrix dimension will also be m x n.

Matrix addition is commutative, i.e., A + B = B + A

### Subtraction

Just like in addition, if two matrices are of the same dimensions, say m x n, then they can be subtracted as well, and the output matrix dimension will also be m x n.

### Multiplication

Multiplication of the matrix is done in two ways:

#### Scalar Multiplication

Scaler multiplication involves multiplying a scalar quantity by a matrix. In scalar multiplication, each element of a matrix is multiplied by the scaler value.

#### Matrix Multiplication

Multiplication of a matrix with another matrix is called matrix multiplication. It is a little complicated. Multiplication of two matrices A x B is possible only if the order of A is m x n and the order of B is n x p. It means the number of columns of matrix A must be equal to the number of rows of matrix B, and the output matrix will be of dimension m x p.

##### Example of Matrix Multiplication

The multiplication of matrices is not commutative, i.e, A + B is not equal to B + A

### Transpose

If A is a matrix of order m x n, then the matrix of order n x m obtained by interchanging rows and columns is called the transpose of a matrix. The transpose of Matrix A is denoted as A’.

These are the major concepts of matrices used in Machine Learning. You must try your hand at practical problems. Try Matrix Calculator.

## Stay Tuned!!

For system setup for data science with Python, click on the link below.

Keep learning and keep implementing!!

Mukeshgood basics !!

Nidhi BansalThank you so much for appreciation.