πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Vector and Matrix Norms

Linear AlgebraVector Norms🟒 Free Lesson

Advertisement

Vector and Matrix Norms

What is a Norm

A norm is a function from a vector space to the non-negative real numbers that satisfies four fundamental axioms:

AxiomPropertyDescription
1Non-negativity for all
2Definiteness
3Homogeneity for all scalars
4Triangle Inequality for all

A vector space equipped with a norm is called a normed vector space. The norm induces a natural distance function , making it a metric space.

Vector Norms

NormFormulaWhen to Use
L1 (Manhattan)Sparse solutions, feature selection (Lasso)
L2 (Euclidean)Smooth solutions, general-purpose (Ridge)
L∞ (Max Norm)Worst-case analysis, adversarial robustness
Lp (General)Interpolation between L1 and L∞
L0 (Pseudo-norm)Cardinality (non-convex, NP-hard to optimize)

Step-by-Step Example: Computing Vector Norms

Matrix Norms

The Frobenius norm treats a matrix as a vector in and computes its Euclidean norm. It equals the square root of the sum of squared singular values.

The spectral norm measures the maximum "stretch" factor of a linear transformation. It equals the largest singular value.

The nuclear norm (also called the trace norm) is the convex envelope of the rank function over the unit spectral norm ball. It is used in matrix completion and low-rank approximation.

Comparison of Matrix Norms

NormFormulaUse Case
FrobeniusGeneral matrix similarity, reconstruction error
SpectralStability analysis, condition number, Lipschitz constants
NuclearMatrix completion, low-rank recovery
L1 (entry-wise)Sparse matrix recovery
L∞ (entry-wise)Bounded perturbations

Induced (Operator) Norms

An induced norm (also called an operator norm) measures the maximum output norm given an input constrained to unit norm. The most common induced norms are:

Induced NormDefinitionFormula
Induced 2-norm
Induced 1-norm
Induced ∞-norm

Example: Computing Matrix Norms

Norm Equivalence

Unit Ball: Geometric Interpretation

The unit ball of a norm is the set . Its shape reveals the geometric character of the norm.

NormUnit Ball ShapeGeometry
L1Diamond (rotated square in 2D)Vertices at and
L2Circle / SphereSmooth, rotationally symmetric
L∞Square / HypercubeVertices at
Lp (1 < p < ∞)Rounded polygonInterpolates between diamond and circle

The L1 unit ball's "pointy" vertices at the axes explain why L1 optimization produces sparse solutions β€” the optimal point is more likely to land on a vertex where some coordinates are exactly zero.

Norms in Optimization

PenaltyNameEffect
LassoSparse solutions, automatic feature selection
RidgeSmall weights, no feature selection
Elastic NetCombines sparsity and smoothness
MinimaxBounded maximum coefficient

Distance Metrics

A norm induces a distance metric that satisfies:

  1. Non-negativity:
  2. Identity:
  3. Symmetry:
  4. Triangle inequality:
DistanceFormulaUse Case
Manhattan ()Grid-based movement, high-dimensional data
Euclidean ()Geometric distance, clustering
Chebyshev ()Warehouse logistics, robotics

Python Implementation

import numpy as np

# --- Vector Norms ---
x = np.array([1, -2, 3, -4])

l1 = np.linalg.norm(x, ord=1)           # L1: 10.0
l2 = np.linalg.norm(x, ord=2)           # L2: sqrt(30) β‰ˆ 5.477
linf = np.linalg.norm(x, ord=np.inf)    # L∞: 4.0
l4 = np.linalg.norm(x, ord=4)           # L4: 354^(1/4) β‰ˆ 4.34

print(f"L1: {l1}, L2: {l2:.4f}, L∞: {linf}, L4: {l4:.4f}")

# --- Matrix Norms ---
A = np.array([[1, 2], [3, 4]])

frob = np.linalg.norm(A, ord='fro')     # Frobenius: sqrt(30) β‰ˆ 5.477
spectral = np.linalg.norm(A, ord=2)     # Spectral: largest singular value
nuclear = np.linalg.norm(A, ord='nuc')  # Nuclear: sum of singular values

print(f"Frobenius: {frob:.4f}")
print(f"Spectral: {spectral:.4f}")
print(f"Nuclear: {nuclear:.4f}")

# --- Induced Norms ---
induced1 = np.linalg.norm(A, ord=1)     # Induced 1-norm: max column sum
induced_inf = np.linalg.norm(A, ord=np.inf)  # Induced ∞-norm: max row sum
print(f"Induced 1-norm: {induced1}")
print(f"Induced ∞-norm: {induced_inf}")

# --- Distance Computation ---
from scipy.spatial.distance import cdist, pdist

points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
dist_l1 = cdist(points, points, metric='cityblock')   # Manhattan
dist_l2 = cdist(points, points, metric='euclidean')   # Euclidean
dist_linf = cdist(points, points, metric='chebyshev') # Chebyshev

# --- Regularization Comparison ---
from sklearn.linear_model import Lasso, Ridge

np.random.seed(42)
X = np.random.randn(100, 10)
true_coef = np.zeros(10)
true_coef[:3] = [3, -2, 1]  # Only 3 non-zero features
y = X @ true_coef + np.random.randn(100) * 0.1

lasso = Lasso(alpha=0.1).fit(X, y)
ridge = Ridge(alpha=0.1).fit(X, y)

print(f"Lasso coefficients: {np.round(lasso.coef_, 3)}")  # Sparse
print(f"Ridge coefficients: {np.round(ridge.coef_, 3)}")  # Small but non-zero

Applications in AI/ML

Common Mistakes

MistakeWhy It's WrongCorrect Approach
Using L0 norm for optimizationL0 is non-convex, NP-hardUse L1 as convex relaxation
Confusing with Frobenius sums all singular values, spectral takes the max
Forgetting Homogeneity requires absolute value on scalar, not
Assuming all norms are equal in infinite dimensionsNorm equivalence requires finite dimensionsIn function spaces, different norms define different topologies
Using L2 norm for sparse feature selectionL2 shrinks but doesn't zero out featuresUse L1 (Lasso) or Elastic Net
Ignoring norm when computing condition number depends on the normChoose the norm appropriate for your error metric

Interview Questions

Q1: Why does L1 regularization produce sparse solutions while L2 does not?

Q2: What is the relationship between the spectral norm and the Frobenius norm?

Q3: When would you use the nuclear norm instead of the Frobenius norm?

Q4: Prove that the L∞ norm is indeed a norm on .

Q5: What is the condition number of a matrix, and why does the norm matter?

Q6: How do norms relate to convergence in optimization algorithms?

Practice Problems

Problem 1: Compute the L1, L2, L∞, and L4 norms of .

Problem 2: Verify the Cauchy-Schwarz inequality for and .

Problem 3: Compute the Frobenius and spectral norms of .

Problem 4: Show that for any vector : .

Quick Reference

Cross-References

  • Vector Spaces: Foundation for defining norms
  • Eigenvalues and Singular Values: Used to compute spectral and nuclear norms
  • Inner Products: Cauchy-Schwarz inequality connects norms to inner products
  • Optimization: Regularization, gradient descent, constrained optimization
  • Machine Learning: Lasso, Ridge, Elastic Net, adversarial robustness
  • Numerical Linear Algebra: Condition numbers, stability analysis
  • Clustering: K-means uses Euclidean norm, K-medians uses L1
  • Dimensionality Reduction: PCA minimizes Frobenius norm reconstruction error

Need Expert Mathematics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement