๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #20

Vector Norms

A norm measures the "size" or "length" of a vector as a single non-negative number. Different norms define "size" differently โ€” and that choice directly shapes how regularization and gradient clipping behave in deep learning.

The Common Norms

NormFormulaAlso Called
L1 norm\(\|\mathbf{x}\|_1 = \sum_i |x_i|\)Manhattan norm
L2 norm\(\|\mathbf{x}\|_2 = \sqrt{\sum_i x_i^2}\)Euclidean norm
L∞ norm\(\|\mathbf{x}\|_\infty = \max_i |x_i|\)Max norm
General Lp norm\(\|\mathbf{x}\|_p = \left(\sum_i |x_i|^p\right)^{1/p}\)โ€”

Numerical Example

\[ \mathbf{x} = [3, -4] \] \[ \|\mathbf{x}\|_1 = |3|+|-4| = 7, \qquad \|\mathbf{x}\|_2 = \sqrt{3^2+(-4)^2} = \sqrt{25} = 5, \qquad \|\mathbf{x}\|_\infty = \max(3,4) = 4 \]

L1 vs L2 โ€” Why the Shape of Their "Unit Circle" Matters

L1 unit "circle" (diamond) L2 unit circle (round)

The L1 norm's sharp corners (on the axes) are why L1 regularization tends to push weights to exactly zero; the L2 norm's smooth boundary shrinks weights toward zero without eliminating them.

Code

import numpy as np
x = np.array([3.0, -4.0])
print(np.linalg.norm(x, ord=1))    # 7.0
print(np.linalg.norm(x, ord=2))    # 5.0
print(np.linalg.norm(x, ord=np.inf))  # 4.0
import torch
x = torch.tensor([3.0, -4.0])
print(torch.norm(x, p=1))   # tensor(7.)
print(torch.norm(x, p=2))   # tensor(5.)

Where This Shows Up in Deep Learning

  • L2 regularization / weight decay: adds \(\lambda\|\mathbf{w}\|_2^2\) to the loss to discourage large weights and reduce overfitting (see L2 Regularization).
  • L1 regularization: adds \(\lambda\|\mathbf{w}\|_1\) โ€” its sharp-cornered geometry tends to drive some weights to exactly zero, producing sparse models (see L1 Regularization).
  • Gradient clipping: rescales a gradient vector so its L2 norm doesn't exceed a threshold, preventing exploding gradients (see Gradient Clipping).

Common Mistakes

  • Assuming "norm" always means the Euclidean (L2) length โ€” always check which \(p\) is intended, since L1 and L2 regularization produce meaningfully different model behavior.
  • Confusing a vector's norm with "distance" in general โ€” a norm measures a single vector's size; distance between two points is the norm of their difference, \(\|\mathbf{a}-\mathbf{b}\|\).

Interview Relevance

Q: "Why does L1 regularization tend to produce sparse weights while L2 doesn't?" Geometrically, the L1 norm's constraint region has sharp corners exactly on the coordinate axes (where some weights are exactly zero), and the loss's optimal point tends to land on those corners. The L2 norm's constraint region is smooth (a sphere), so its optimum shrinks weights toward zero without usually reaching it exactly.

Practice Question

Compute the L1, L2 and L∞ norms of \([1, -2, 2]\) by hand, then verify with code.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Vector Norms โ€“ FAQs

Quick answers about learning Vector Norms in Deep Learning.

This free note from CodingNow 2.0 explains Vector Norms in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Vector Norms, is 100% free with no signup required.
With focused practice, most students grasp Vector Norms in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now