Linear Transformations and Geometry
Linear algebra is not just about numbers in tables—it’s about transformations of space. Matrices can be seen as functions that transform vectors, stretching, rotating, reflecting, or projecting them. Understanding these transformations geometrically is essential for intuition in machine learning.
Linear Transformations
A function
- Additivity:
- Homogeneity:
for scalar
Every linear transformation can be represented as a matrix multiplication:
for some matrix
Geometric Interpretations
Scaling – Multiply vectors by a scalar.
Example:scales by 2 and by 3. Rotation – Preserve length but rotate direction.
Example (2D rotation by): Reflection – Flip across a line or plane.
Projection – Collapse vectors onto a subspace.
Example: Project onto-axis in 2D:
Mini Examples
Stretching:
doubles the
-axis component while leaving unchanged. Rotation by 90°:
rotates any vector counterclockwise by 90°.
Projection:
projects vectors onto the
-axis.
Hands-on with Python and Rust
import numpy as np
v = np.array([1, 2])
# Scaling
A = np.array([[2, 0], [0, 3]])
scaled = A.dot(v)
# Rotation (90 degrees)
R = np.array([[0, -1], [1, 0]])
rotated = R.dot(v)
# Projection onto x-axis
P = np.array([[1, 0], [0, 0]])
projected = P.dot(v)
print("Original vector:", v)
print("Scaled:", scaled)
print("Rotated:", rotated)
print("Projected:", projected)
use ndarray::{array, Array1, Array2};
fn main() {
let v: Array1<f64> = array![1.0, 2.0];
// Scaling
let a: Array2<f64> = array![[2.0, 0.0], [0.0, 3.0]];
let scaled = a.dot(&v);
// Rotation (90 degrees)
let r: Array2<f64> = array![[0.0, -1.0], [1.0, 0.0]];
let rotated = r.dot(&v);
// Projection onto x-axis
let p: Array2<f64> = array![[1.0, 0.0], [0.0, 0.0]];
let projected = p.dot(&v);
println!("Original vector: {:?}", v);
println!("Scaled: {:?}", scaled);
println!("Rotated: {:?}", rotated);
println!("Projected: {:?}", projected);
}
Connection to ML
- Scaling → standardization of features.
- Rotation → PCA rotates data into new basis.
- Projection → dimensionality reduction (projecting onto lower-dimensional subspaces).
- Reflections & symmetries → used in data augmentation and transformations.
Next Steps
Continue to Subspaces and Basis.