1.1 Introduction to Vectors & Vector Operations
Welcome to the beginning of your linear algebra journey for Machine Learning! In this lecture, we will explore the absolute fundamental building block of all data science and AI algorithms: the Vector.
If you have ever worked with tables of data, you have already used vectors without realizing it. Let's demystify what a vector actually is and how we perform basic operations on it.
1. What is a Vector?
A vector can be understood through two main perspectives: the Algebraic View (the language of computer science and statistics) and the Geometric View (the language of physics and spatial visualization).
The Algebraic View: A List of Numbers
To a computer scientist or machine learning engineer, a vector is simply an ordered list of numbers. Each number in the list represents a specific feature or measurement of an object.
-
Example: Imagine you are building an algorithm to predict house prices. For a single house, you collect:
- Size:
- Number of bedrooms:
- Distance to city center:
We can group these numbers into a column vector, which we usually denote with a bold lowercase letter like :
This is a 3-dimensional vector because it contains 3 distinct measurements.
The Geometric View: An Arrow in Space
Geometrically, a vector is an arrow starting from a reference point (usually the origin in a coordinate system) and pointing to a specific coordinate.
- The length of the arrow represents the magnitude (size).
- The direction of the arrow shows where it is pointing.
For instance, a 2D vector represents an arrow starting at and pointing to the coordinate on a grid.
2. Key Vector Operations
To use vectors in machine learning, we need to perform math operations on them. The two most fundamental operations are Vector Addition and Scalar Multiplication.
Vector Addition: Combining Vectors
When we add two vectors of the same dimension, we add their corresponding elements one by one.
- Example: If and , then:
Geometric Interpretation: The "Tip-to-Tail" Method
To visualize addition:
- Start at the origin and draw the first vector .
- Take the second vector and place its starting point (tail) at the tip of vector .
- Draw a new arrow from the origin straight to the tip of vector . This new arrow is the resulting vector .
Vector Subtraction: Finding the Difference
Vector subtraction works similarly to addition, but we subtract the corresponding elements.
Geometrically, can be visualized as adding the negative of to :
The resulting vector represents the path from the tip of to the tip of .
Scalar Multiplication: Scaling Space
A scalar is a single real number (like , , or ). When we multiply a vector by a scalar, we multiply every element in the vector by that number.
- If : The vector stretches (grows longer).
- If : The vector shrinks (gets shorter).
- If (Negative): The vector reverses direction and points the opposite way.
3. Hands-on Experiment
Try out vector operations yourself using the interactive sandbox below. Switch between ADD, SUB, and SCALE using the controls, and adjust the coordinates of the vectors to see how the mathematical formulas and geometric arrows change in real-time.