Introduction
Welcome to the first lesson of our module on Linear Algebra for Machine Learning! In our previous module, you mastered the principles of formal logic, which provide the structure for computational reasoning and classical AI. You learned how to build and verify logical arguments, a process that underpins algorithm design.
Now, we shift from the logic of reasoning to the mathematics of data. Modern AI, especially machine learning and neural networks, is built on the ability to process and find patterns in vast quantities of data. Linear algebra is the language we use to represent and manipulate this data efficiently.
Today's learning outcome is to perform vector addition, scalar multiplication, and compute dot products. These are the three most fundamental operations in linear algebra. Think of this as learning the alphabet and basic grammar of the language that powers today's most advanced AI systems. Mastering these operations is the first essential step toward understanding how an AI model "sees" an image, "reads" text, or "analyzes" a dataset.
1. Understanding Vectors: The Building Blocks of Data
Before we can operate on vectors, we need a clear understanding of what they are. In the context of machine learning, a vector can be seen in two complementary ways: as a geometric object with direction and length, and as a list of numbers representing a point in space.
To build this dual intuition, let's start with a video that beautifully illustrates these perspectives.
Vectors | Chapter 1, Essence of linear algebra
This video from the excellent 'Essence of linear algebra' series by 3Blue1Brown will help you visualize vectors and understand how they are represented.
Watch the first part of the video (00:00 - 04:28). Pay close attention to the distinction between the 'physics' (arrow in space), 'computer science' (ordered list of numbers), and 'mathematician' (abstract) views. For our purposes, we will combine the physics and computer science views: a vector is an arrow rooted at the origin, whose coordinates are an ordered list of numbers.
As the video explains, a vector is fundamentally a way to store a piece of data that has multiple attributes. For instance:
- A 2D vector
[x, y]could represent a point on a map. - A 3D vector
[r, g, b]could represent a color. - A vector with hundreds of dimensions could represent a single user's preferences on a streaming service, with each dimension corresponding to a different movie genre.
In machine learning, we almost always work with the numerical representation, but the geometric intuition is crucial for understanding what our operations are actually doing to the data.
2. Combining and Scaling Vectors
The two most basic things we can do with vectors are add them together and scale them. These operations form the foundation of everything else in linear algebra.
Vector Addition
Geometrically, adding two vectors, and , means placing the tail of at the tip of . The sum, , is the new vector drawn from the origin to the tip of . You can think of this as chaining two movements together.
Numerically, the process is simpler: we just add the corresponding components.
If and , then:

Scalar Multiplication
A scalar is just a regular number (not a vector). Multiplying a vector by a scalar "scales" it.
- Multiplying by a scalar stretches the vector.
- Multiplying by a scalar shrinks it.
- Multiplying by a negative scalar reverses its direction and scales it.
Numerically, you multiply every component of the vector by the scalar.
If is a scalar and , then:
Let's watch the next segment of the 3Blue1Brown video to see these two operations in action.
Vectors | Chapter 1, Essence of linear algebra
This segment continues from where we left off, providing a clear, animated explanation of vector addition and scalar multiplication.
Watch from 04:28 to 08:14. Notice how the geometric action (e.g., stretching a vector) directly corresponds to the numerical operation (e.g., multiplying each component).
From Theory to Practice: NumPy
Your goal is to build intelligent systems, which means you'll be implementing these concepts in code. Python's NumPy library is the standard tool for numerical computation. Let's see how these operations look in practice.
Introduction to Linear Algebra for Applied Machine Learning
This article, 'Introduction to Linear Algebra for Applied Machine Learning', provides the formal definitions and shows how to perform these operations in NumPy.
Read the sections titled 'Basic vector operations', 'Vector-vector addition', and 'Vector-scalar multiplication'. You can skip the part on 'Linear combinations' for now, but notice that it's simply a combination of the two operations you've just learned. Compare the mathematical formulas with the NumPy code examples.
3. Measuring Relationships: The Dot Product
We can now add and scale vectors. But how do we measure the relationship between two vectors? For instance, how "similar" are they? Do they point in the same direction? Are they perpendicular? This is the role of the dot product (also called the scalar product or inner product).
The dot product of two vectors, and , produces a single number (a scalar). It has a geometric and an algebraic definition that are equivalent.
-
Algebraic Definition: Multiply the corresponding components and sum the results.
This is how you'll usually compute it.
-
Geometric Definition: Multiply the lengths of the two vectors and the cosine of the angle between them.
Where denotes the length (or magnitude) of vector , and is the angle between and . This definition gives us the intuition.

Let's watch a video that focuses on the intuition behind the dot product.
The meaning of the dot product | Linear algebra makes sense
This video from Looking Glass Universe provides a fantastic conceptual breakdown of what the dot product represents.
Watch the first 5 minutes of the video (00:00 - 05:04). The key insight is to think of the dot product as a measure of 'how much two vectors point in the same direction'.
The sign of the dot product tells us about the angle between the vectors:
- Positive (): The angle is less than 90°. The vectors point in generally the same direction.
- Zero (): The angle is exactly 90°. The vectors are orthogonal (perpendicular). This is an extremely important property used throughout machine learning, for example, to find independent features in data.
- Negative (): The angle is greater than 90°. The vectors point in generally opposite directions.
Now, let's look at how to compute this in NumPy.
Introduction to Linear Algebra for Applied Machine Learning
Returning to the same article, we'll see the formula and code for the dot product.
Read the section 'Vector-vector multiplication: dot product'. Notice the use of .T (transpose) and @ (matrix multiplication operator in Python 3.5+) to compute the dot product. This is a common and efficient way to do it in NumPy.
Conclusion
In this lesson, you've taken your first steps into the mathematical world that underpins modern AI. You moved from the discrete rules of logic to the continuous space of data represented by vectors.
Key Takeaways:
- Vectors as Data: Vectors are ordered lists of numbers that represent data points in a high-dimensional space.
- Vector Addition: Combines vectors by adding their corresponding components. Geometrically, it's like following one vector's path and then the other's.
- Scalar Multiplication: Scales a vector's magnitude and/or reverses its direction by multiplying every component by a single number.
- Dot Product: A crucial operation that results in a scalar. It measures the alignment between two vectors, with its sign indicating whether they point in similar, perpendicular, or opposite directions. A dot product of zero means the vectors are orthogonal.
These three operations—addition, scalar multiplication, and the dot product—are the foundational tools you will use repeatedly. They are the simple arithmetic from which complex models are built.
Preview of the Next Lesson:
Now that you can operate on individual vectors, the next logical step is to operate on entire sets of vectors at once. In the next lesson, you will learn to multiply matrices and vectors. This will introduce you to matrices as objects that can transform vectors or entire spaces of data—scaling, rotating, and shearing them. This concept of transformation is central to how linear regression models and neural networks process and learn from data.