Hello! Welcome to your first lesson in the course "Learn computer vision from scratch." I'm excited to guide you on this journey.
Given your goal of understanding computer vision deeply, we'll start with the essential mathematical language used to describe and manipulate data: linear algebra. This first module, "Mathematical Foundations for Machine Learning," will equip you with the tools to understand how algorithms "see" and process images.
In this lesson, we will focus on the absolute fundamentals. By the end, you'll be able to define vectors and matrices and perform fundamental operations: addition, scalar multiplication, and transposition. These concepts form the bedrock for everything that follows, from representing pixels in an image to building complex neural networks.
Since you can dedicate about 30 minutes per day, this lesson is structured in two main parts. You can comfortably complete the first part on vectors in one session and the second part on matrices in the next.
1. Vectors: The Building Blocks of Data
In machine learning and computer vision, we need a way to represent data numerically. Whether it's the features of an object, the color of a pixel, or the parameters of a model, we use vectors.
At its core, a vector is simply an ordered list of numbers. To get a formal definition and see how these are represented, let's start with our first reading.
Introduction to Linear Algebra for Applied Machine Learning
This first resource, 'Introduction to Linear Algebra for Applied Machine Learning' by Pablo Insenze, provides a clear and practical introduction to vectors. We'll focus on the core definitions and operations.
Please read the sections titled 'Vectors', 'Types of vectors', 'Vector dimensions and coordinate system', and 'Basic vector operations'. Focus on understanding the R^n representation, the element-wise nature of addition, and the scaling effect of scalar multiplication. You can skim the parts on polynomials and geometric vectors, as our main focus will be on the R^n representation used in computing.
As you've just read, while vectors can be abstract concepts, for our purposes, we'll primarily think of them as arrays of numbers. A vector in is a list of real numbers, which we can use to represent a point in an -dimensional space.
For example, in computer vision, a single color pixel is often represented by a vector of three numbers, like , corresponding to the intensity of red, green, and blue. This is a vector in .
Key Vector Operations
From the reading, you've seen two fundamental operations. Let's formalize them.
1. Vector Addition
If we have two vectors and of the same dimension , their sum is found by adding the corresponding elements:
This operation is commutative () and associative ().
2. Scalar Multiplication
Multiplying a vector by a single number (a scalar) scales the vector. Every element of the vector is multiplied by the scalar:
Geometrically, this changes the vector's magnitude (length) but not its direction (unless is negative, in which case the direction is reversed).
Test your understanding!
Let and .
Calculate the vector .
Show answer
First, we perform scalar multiplication on :
Next, we perform vector subtraction (which is addition of the negative vector):
This concludes the first part of our lesson. When you're ready, you can continue to the next section on matrices.
2. Matrices: Organizing Data in Grids
If a vector is a list of numbers, a matrix is a rectangular grid of numbers, arranged in rows and columns. This is an incredibly powerful structure. For instance, a grayscale image can be directly represented as a matrix where each entry is the brightness of a pixel.

A matrix with rows and columns is said to have dimensions . We often denote it as .
Let's return to our primary resource to explore matrices and their fundamental operations.
Introduction to Linear Algebra for Applied Machine Learning
We will now read the sections on matrices from the same guide. Pay close attention to how the operations of addition, scalar multiplication, and transposition are defined.
Please read the section 'Matrices' and the subsections under 'Basic Matrix operations': 'Matrix-matrix addition', 'Matrix-scalar multiplication', and 'Matrix transpose'. Notice how similar the first two operations are to their vector counterparts.
Key Matrix Operations
As you saw, the basic operations for matrices are direct extensions of what we learned for vectors.
1. Matrix Addition and Scalar Multiplication
Just like with vectors, matrix addition and scalar multiplication are performed element-wise.
- Addition: Two matrices and can be added only if they have the same dimensions. The resulting matrix has entries .
- Scalar Multiplication: Multiplying a matrix by a scalar results in a matrix where each element is .
2. Matrix Transposition
The transpose of a matrix , denoted , is a new matrix where the rows of become the columns of , and vice versa. If is an matrix, then is an matrix.
The entry in the -th row and -th column of is the same as the entry in the -th row and -th column of . That is, .
For example:

Implementation in Python with NumPy
Since you have a background in Python, it's time to introduce the primary tool for numerical computing: NumPy. You have no prior experience with it, so let's start slowly. NumPy's main object is the ndarray (n-dimensional array), which we'll use to represent both vectors and matrices.
Here's how you'd perform the operations we've discussed.
import numpy as np
# Create a 2x3 matrix (2 rows, 3 columns)
A = np.array([[1, 2, 3],
[4, 5, 6]])
# Create another 2x3 matrix
B = np.array([[7, 8, 9],
[10, 11, 12]])
# 1. Addition
C = A + B
print("A + B =\n", C)
# 2. Scalar Multiplication
D = 2 * A
print("\n2 * A =\n", D)
# 3. Transposition
A_T = A.T # or A.transpose()
print("\nTranspose of A =\n", A_T)
print("\nShape of A:", A.shape) # Will be (2, 3)
print("Shape of A_T:", A_T.shape) # Will be (3, 2)
Feel free to run this code on your own machine to get a feel for it. Make sure you have NumPy installed (pip install numpy).
Test your understanding!
Let .
Calculate the matrix . What do you notice about the resulting matrix ?
Show answer
First, find the transpose of :
Now, add and :
Observation: The resulting matrix is symmetric. A matrix is symmetric if it is equal to its own transpose (). Notice that the element at row 1, column 2 (-1) is the same as the element at row 2, column 1. This is true for any matrix created by adding a square matrix to its transpose.
Conclusion
Excellent work on completing your first lesson! You've taken the first crucial step into the mathematical world of computer vision.
Let's summarize the key takeaways:
- Vectors are ordered lists of numbers, representing points or directions in space.
- Matrices are rectangular grids of numbers, which can represent datasets, images, or transformations.
- Addition and scalar multiplication are element-wise operations for both vectors and matrices.
- Transposition is a fundamental matrix operation that swaps rows and columns, turning an matrix into an matrix.
These operations may seem simple, but they are the atomic units of the more complex algorithms you will build later.
Preview of the Next Lesson:
In our next lesson, we will move on to two of the most important operations in all of linear algebra: the dot product of vectors and matrix multiplication. You'll discover that matrix multiplication is not an element-wise operation, and understanding how it works is key to unlocking powerful techniques in machine learning.