Matrix Operations
Matrix operations are the basic calculations we perform on matrices. They allow AI systems to add, subtract, scale, and transform groups of numerical values.
Matrix operations are rules for working with matrices.
Once numbers are organized into rows and columns, we can perform mathematical operations on them. These operations are an important part of linear algebra and are used throughout machine learning and AI.
What Is a Matrix Operation?
A matrix operation is simply a mathematical calculation performed on one or more matrices.
For example, suppose we have two matrices:
A = [ 1 2 ] [ 3 4 ] B = [ 5 6 ] [ 7 8 ]
We can perform different operations using these matrices.
Matrix Addition Matrix Subtraction Scalar Multiplication Matrix Multiplication
Each operation follows its own mathematical rule.
Matrix Addition
Matrix addition means adding corresponding values from two matrices.
The two matrices must have the same number of rows and columns.
A = [ 1 2 ] [ 3 4 ] B = [ 5 6 ] [ 7 8 ]
Add the values in the same positions:
A + B [ 1 2 ] [ 5 6 ] [ 3 4 ] + [ 7 8 ] => [ 1+5 2+6 ] [ 3+7 4+8 ] => [ 6 8 ] [ 10 12 ]
So the result is another matrix with the same shape.
Matrix Subtraction
Matrix subtraction works in the same way as matrix addition. We subtract corresponding values.
A = [ 10 20 ] [ 30 40 ] B = [ 1 2 ] [ 3 4 ]
Now subtract each corresponding value:
A - B [ 10-1 20-2 ] [ 30-3 40-4 ] => [ 9 18 ] [ 27 36 ]
Again, both matrices must have the same dimensions.
Scalar Multiplication
A scalar is a single number. We can multiply every value in a matrix by that single number.
For example:
A = [ 1 2 ] [ 3 4 ] Scalar = 3
Multiply every value by 3:
3A
= 3 × [ 1 2 ]
[ 3 4 ]
= [ 3 6 ]
[ 9 12 ]
Notice that the matrix shape does not change. Only the values change.
Why Does Matrix Shape Matter?
The dimensions of a matrix tell us how many rows and columns it contains.
[ 1 2 3 ] [ 4 5 6 ] 2 rows × 3 columns Shape = 2 × 3
Matrix operations often depend on these dimensions.
For example, two matrices can be added only when their shapes are the same.
2 × 2 + 2 × 2 → Allowed 2 × 3 + 2 × 3 → Allowed 2 × 2 + 2 × 3 → Not allowed
Understanding matrix shape becomes especially important when we reach matrix multiplication.
Matrix Transpose
The transpose of a matrix changes its rows into columns and its columns into rows.
A = [ 1 2 3 ] [ 4 5 6 ]
This matrix has 2 rows and 3 columns.
After taking the transpose:
Aᵀ = [ 1 4 ] [ 2 5 ] [ 3 6 ]
The shape changes from 2 × 3 to 3 × 2.
Transpose operations are common in linear algebra, machine learning, and neural network calculations.
Matrix Operations in AI
AI models work with large amounts of numerical data. Matrices provide an efficient way to organize that data.
Matrix operations are then used to transform and process those numerical values.
Input Data
↓
Matrix
↓
Matrix Operations
↓
Transformed Data
↓
AI Model
↓
Prediction
For example, an image can be represented using numerical values. Those values can be organized into matrices and transformed using mathematical operations.
Neural networks also perform many matrix-based calculations during training and prediction.
Putting the Basic Operations Together
Let's review the main operations we have learned.
Matrix Addition
A + B
↓
Add corresponding values
Matrix Subtraction
A - B
↓
Subtract corresponding values
Scalar Multiplication
kA
↓
Multiply every value by k
Transpose
Aᵀ
↓
Rows become columns
These are some of the basic tools we need before learning more advanced matrix calculations.
Matrix operations are rules for calculating with organized numbers.
Matrix addition and subtraction work with corresponding values, scalar multiplication changes every value by the same factor, and transpose changes rows into columns. Understanding these operations gives you the foundation for dot products and matrix multiplication.