ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Linear Algebra Essentials for Machine Learning
Chapter 1: Vectors in Machine Learning
Vectors as Data Representations
Fundamental Vector Operations
Vector Magnitude and Direction
The Dot Product and Projections
Vector Norms: Measuring Length
Calculating Distances Between Vectors
Implementing Vector Operations with NumPy
Hands-on Practical: Feature Vector Manipulation
Quiz for Chapter 1
Chapter 2: Matrices: Data Representation and Transformations
Matrices for Organizing Data
Basic Matrix Operations
Matrix Multiplication Explained
Matrices as Linear Transformations
Common Types of Matrices
Representing Systems of Linear Equations
Implementing Matrix Operations with NumPy
Hands-on Practical: Transforming Data Points
Quiz for Chapter 2
Chapter 3: Solving Linear Systems and Matrix Inverses
Linear Systems in Machine Learning Models
Introduction to Gaussian Elimination
The Matrix Inverse
Calculating the Inverse of a Matrix
The Determinant and Invertibility
Solving Ax=b using the Inverse
Numerical Stability and Alternatives
Hands-on Practical: Solving for Model Coefficients
Quiz for Chapter 3
Chapter 4: Vector Spaces, Subspaces, and Linear Independence
Defining Vector Spaces
Understanding Subspaces
Linear Combinations and Span
Linear Independence of Vectors
Basis and Dimension
Column Space and Null Space
Rank of a Matrix
Hands-on Practical: Analyzing Feature Vector Sets
Quiz for Chapter 4
Chapter 5: Eigenvalues and Eigenvectors
Definition of Eigenvalues and Eigenvectors
Geometric Interpretation
The Characteristic Equation
Calculating Eigenvectors
Eigen-decomposition of a Matrix
Significance in Principal Component Analysis (PCA)
Calculating Eigenvalues/Eigenvectors with NumPy
Hands-on Practical: Eigen-decomposition Calculations
Quiz for Chapter 5
Chapter 6: Matrix Decompositions for Machine Learning
Introduction to Matrix Decompositions
Singular Value Decomposition (SVD)
Geometric Interpretation of SVD
SVD for Dimensionality Reduction
SVD Applications in Data Compression
Relationship between SVD and Eigen-decomposition
Overview of LU Decomposition
Overview of QR Decomposition
Implementing Decompositions with SciPy/NumPy
Hands-on Practical: Applying SVD
Quiz for Chapter 6

Fundamental Vector Operations

Vectors are foundational for representing data in machine learning. We will examine the fundamental operations performed on vectors, which form the primary building blocks for many machine learning algorithms. These include addition, subtraction, and scalar multiplication, exploring both their mathematical definitions and geometric interpretations.

Vector Addition

Adding two vectors is straightforward: you add their corresponding elements. If you have two vectors vvv and www of the same dimension (say, in Rn\mathbb{R}^nRn), their sum v+wv + wv+w is a new vector where each element is the sum of the elements at the same position in vvv and www.

Mathematically, if v=[v1,v2,...,vn]v = [v_1, v_2, ..., v_n]v=[v1​,v2​,...,vn​] and w=[w1,w2,...,wn]w = [w_1, w_2, ..., w_n]w=[w1​,w2​,...,wn​], then: v+w=[v1+w1,v2+w2,...,vn+wn]v + w = [v_1 + w_1, v_2 + w_2, ..., v_n + w_n]v+w=[v1​+w1​,v2​+w2​,...,vn​+wn​]

Geometric Interpretation: Geometrically, vector addition can be visualized using the "tip-to-tail" method or the parallelogram rule. Imagine placing the tail of vector www at the tip of vector vvv. The resulting vector v+wv + wv+w starts at the origin (tail of vvv) and ends at the new tip of www. Alternatively, if you form a parallelogram with vvv and www starting from the origin, the diagonal of the parallelogram starting from the origin represents the sum v+wv + wv+w.

Let's visualize this with two 2D vectors, v=[2,1]v = [2, 1]v=[2,1] and w=[1,3]w = [1, 3]w=[1,3]. Their sum is v+w=[2+1,1+3]=[3,4]v + w = [2+1, 1+3] = [3, 4]v+w=[2+1,1+3]=[3,4].

The vector vvv (blue) is added to www (green, solid line starting from vvv's tip) using the tip-to-tail method. The resultant vector v+wv+wv+w (orange) goes from the origin to the final tip. The dashed green vector shows www starting from the origin.

Vector Subtraction

Similar to addition, vector subtraction involves subtracting corresponding elements. For vectors vvv and www of the same dimension: v−w=[v1−w1,v2−w2,...,vn−wn]v - w = [v_1 - w_1, v_2 - w_2, ..., v_n - w_n]v−w=[v1​−w1​,v2​−w2​,...,vn​−wn​]

Geometric Interpretation: Vector subtraction v−wv - wv−w can be thought of as adding the negative of vector www to vvv, i.e., v+(−w)v + (-w)v+(−w). The vector −w-w−w has the same magnitude as www but points in the opposite direction. Geometrically, the vector v−wv - wv−w is the vector that starts at the tip of www and ends at the tip of vvv, when both vvv and www start from the origin. This vector represents the displacement from www to vvv.

For example, let v=[4,2]v = [4, 2]v=[4,2] and w=[1,3]w = [1, 3]w=[1,3]. Then v−w=[4−1,2−3]=[3,−1]v - w = [4-1, 2-3] = [3, -1]v−w=[4−1,2−3]=[3,−1].

The vectors vvv (blue) and www (green) start from the origin. The vector v−wv-wv−w (orange) represents the displacement from the tip of www to the tip of vvv.

Scalar Multiplication

Scalar multiplication involves multiplying a vector by a single number (a scalar). This operation scales the vector's magnitude and potentially reverses its direction if the scalar is negative. If ccc is a scalar and v=[v1,v2,...,vn]v = [v_1, v_2, ..., v_n]v=[v1​,v2​,...,vn​] is a vector: cv=[cv1,cv2,...,cvn]c v = [c v_1, c v_2, ..., c v_n]cv=[cv1​,cv2​,...,cvn​]

Geometric Interpretation: Multiplying a vector vvv by a scalar ccc results in a new vector pointing in the same direction as vvv if c>0c > 0c>0, and in the opposite direction if c<0c < 0c<0. The magnitude (length) of the resulting vector is ∣c∣|c|∣c∣ times the magnitude of the original vector vvv. If c=0c = 0c=0, the result is the zero vector.

For example, if v=[2,1]v = [2, 1]v=[2,1] and c=2.5c = 2.5c=2.5: 2.5v=[2.5×2,2.5×1]=[5,2.5]2.5 v = [2.5 \times 2, 2.5 \times 1] = [5, 2.5]2.5v=[2.5×2,2.5×1]=[5,2.5] This new vector points in the same direction as vvv but is 2.5 times longer.

If c=−1c = -1c=−1: −1v=[−1×2,−1×1]=[−2,−1]-1 v = [-1 \times 2, -1 \times 1] = [-2, -1]−1v=[−1×2,−1×1]=[−2,−1] This vector has the same length as vvv but points in the opposite direction.

The original vector vvv (blue), scaled by 2.5 (orange), and scaled by -1 (purple). Scaling stretches or shrinks the vector and can reverse its direction.

These fundamental operations, addition, subtraction, and scalar multiplication, are essential tools. They allow us to combine and manipulate vector representations of data, forming the basis for more complex algorithms and transformations we'll encounter later, such as calculating centroids, updating model parameters, or projecting data. In the upcoming sections, we'll see how to perform these efficiently using Python's NumPy library.

  • Introduction to Linear Algebra, Gilbert Strang, 2016 (Wellesley-Cambridge Press) - A widely respected textbook providing a fundamental understanding of linear algebra concepts, including clear explanations of vector operations and their geometric representations.
  • Mathematics for Machine Learning, Marc Peter Deisenroth, A. Aldo Faisal, and Cheng Soon Ong, 2020 (Cambridge University Press) - This book provides a solid mathematical foundation for machine learning, covering vector operations from a perspective highly relevant to ML practitioners.
  • Linear Algebra (MIT OpenCourseWare Course 18.06), Gilbert Strang, 2010 (MIT OpenCourseWare) - A classic online course offering video lectures and lecture notes that provide intuitive geometric interpretations for basic vector operations.

© 2026 ApX Machine Learning