Vectors and Matrices
What is it?
A vector is an ordered list of numbers. Geometrically, it represents an arrow with a direction and a length (magnitude).
A matrix is a 2D rectangular grid of numbers organized into rows and columns. In machine learning, matrices bundle many data points together or represent linear transformations that stretch, rotate, or project data.
Why we need it
Computers cannot look at a picture of a cat or read a patient's medical history directly. They only process numbers.
Linear algebra allows us to turn any real-world object into numbers:
- A house is represented as a feature vector: .
- An entire dataset of houses is organized into a matrix of shape .
- An image is a matrix of pixel brightness values (or a 3D tensor with red, green, and blue channels).
- Neural network weights that transform input features into predictions are stored as matrices.
Linear algebra gives machine learning a unified mathematical language to manipulate millions of numbers simultaneously.
Explained in detail
1. The Two Ways to Think About a Vector
There are two equally helpful ways to view a vector :
- Computer scientist's view: An ordered list of features. Here, and .
- Physicist's view: An arrow starting at the origin and pointing to coordinate .
The length of this arrow is called its magnitude or norm, written . Using the Pythagorean theorem:
Think of a vector as driving directions: "drive 3 blocks East, then 2 blocks North". No matter where you start, that instruction is the same displacement.
2. Vector Addition: The Parallelogram Rule
When you add two vectors and , you add their matching components:
Geometrically, this is "tip-to-tail" addition. Take vector , place its tail at the tip of , and the combined journey from origin to final destination is . This forms a parallelogram.
3. Scalar Multiplication: Scaling and Flipping
A single regular number is called a scalar. Multiplying a vector by a scalar multiplies every single component:
- If : the arrow stretches in the same direction.
- If : the arrow shrinks.
- If : the arrow flips and points in the opposite direction.
4. From Vectors to Matrices
When we stack multiple column vectors side by side, we get a matrix:
A matrix with rows and columns has dimension . In ML:
- Row usually represents the -th example (e.g. house #42).
- Column represents the -th feature (e.g. square footage across all houses).
Interactive 2D Vectors & Vector Addition
Drag any dot on the canvas (blue v, orange u, or green v + u), or click any coordinate / magnitude box in the instrument panel to edit values dynamically.
What to try
- Drag the blue dot (vector ) and orange dot (vector ) anywhere around the grid.
- Notice the green arrow (): see how the dashed lines complete the parallelogram.
- Move the Scalar slider (): watch vector grow, shrink, and flip direction when turns negative.
- Check the live values panel to observe how the coordinates and magnitudes update in real time.
- Click the "Orthogonal (90Β°)" preset to see two perpendicular vectors.
- Click "Collinear (Parallel)" to see vectors lying along the exact same line.
Notes & Formula
In machine learning conventions, standard vectors are almost always column vectors unless transposed () into row vectors.
Common mistake: Adding vectors of different lengths. Vector addition is only defined when both vectors have the exact same number of dimensions.
Quiz
π§©
Ready to test yourself?
12 questions Β· explanations shown after
Teach & Solidify
Teach This: Vectors and Matrices
Core Intuition
A vector is an arrow representing features or direction in space; a matrix is a grid of vectors that stores entire datasets or transforms space.
Key Concepts to Explain
- 1Vector addition (u + v) combines displacement tip-to-tail (parallelogram rule).
- 2Scalar multiplication (c Β· v) stretches, shrinks, or flips direction (when c < 0).
- 3In ML tabular datasets, row i is an example/sample, while column j is a feature.
β οΈ What Most Students Get Confused About
Confusing vector addition with scalar addition: you can only add vectors that share the exact same number of dimensions!
Explain Vectors and Matrices in your own words
Imagine you are explaining this idea to a friend or classmate with no math background. Writing it out forces your brain to bridge gaps in your intuition.
Resources & GitHub
Resources & Study Materials
Deepen your understanding with author-prepared study notes, derivation proofs, and curated educational lectures.
Grant Sanderson (3Blue1Brown) introduces the coordinate vs geometric view of vectors.
Free university textbook by Deisenroth, Faisal & Ong covering vectors, spaces, and linear independence.
Python syntax reference for array shapes, dot products, and vector norms.
Mastered this concept?
Tick this box when you feel confident explaining it.
Topic Resources
Vectors_and_Matrices_Summary.md
Markdown Note567 B Β· Modified Latest
Was this clear?