Matrices and vectors are essential components of many modern AI algorithms. It’s pretty crucial to have a solid understanding of matrix and vector fundamentals if you want to be an effective AI engineer. In this post I will quickly summarize some of the most basic operations on matrices and vectors.
A matrix is a set of scalar quantities arranged in a rectangular array. A matrix with N rows and M columns is said to be a NxM matrix. For example, the following is a 3x2 (three by two) matrix because it has three rows and two columns:
[ab cd ef]
Matrices are used in a wide variety of AI algorithms. For example, in computer vision matrices are used to represent images (the size of the matrix in that case is the height of the image by the width). This representation allows us to transform images (blur, sharpen, gamma correction, etc) and even detect features in images (edges, corners, etc) using straightforward matrix operations.
Basic Matrix Operations
Matrix Addition and Subtraction
Two of the simplest operations we can do with two matrices are addition and subtraction. To add or subtract two matrices, we simply add or subtract the elements at corresponding positions in the two matrices. Note that this implies that two matrices must have an equal number of rows and columns to be added.
[ab cd]+[ef gh]=[(a+e)(b+f) (c+g)(d+h)]
Scalar Multiplication
Multiplying scalars by matrices is also a very simple operation. To compute the product of a scalar multiplied by a matrix, we multiply every entry in the matrix by the scalar.
a×[bc de]=[(a×b)(a×c) (a×d)(a×e)]
Transposition
The transpose of a matrix (for matrix A this is denoted as AT), is computed by turning the rows into columns and vice versa.
[abc def]T=[ad be cf]
Equality
Two matrices of same the order (same number of columns and rows) are said to be equal if each of the corresponding elements in the two matrices are equal.