The Math Behind the Methods

L1, L2 and Infinity Norms and Where Each Appears in Learning

Compare the three common vector norms and see how each shapes losses, penalties, gradient clipping, distances and robustness budgets.

Key takeaways

  • L1 sums absolute values, L2 takes the root of the summed squares, and the infinity norm takes the maximum absolute value.
  • Squared L2 error pulls a constant prediction to the mean, while L1 error pulls it to the median.
  • An L1 penalty can set weights exactly to zero; a squared L2 penalty shrinks them smoothly.
  • Clipping a gradient by its L2 norm keeps its direction, while clipping each entry can change it.
  • Compare norms only after thinking about feature scales and the number of dimensions.

A norm is a rule for measuring the size of a vector. The L1 norm adds the absolute values of the entries, the L2 norm is the ordinary straight-line length, and the infinity norm is the largest absolute entry. They agree on which vector is zero and disagree about which of two nonzero vectors is bigger.

That disagreement has practical effects. The norm you place in a loss, a penalty or a limit decides what your training procedure tolerates and what it punishes.

Definitions on one vector

For a vector x with d entries:

‖x‖₁  = |x₁| + |x₂| + ... + |x_d|
‖x‖₂  = √(x₁² + x₂² + ... + x_d²)
‖x‖∞  = max over i of |x_i|

Take x = (3, −4, 0). The L1 norm is 7, the L2 norm is 5 and the infinity norm is 4.

All three are members of one family, the p-norms, where you raise absolute values to the power p, add them and take the p-th root. As p grows, the largest entry dominates and the result approaches the maximum.

A proper norm is never negative, is zero only for the zero vector, scales with the absolute value of any multiplier and obeys the triangle inequality: ‖a + b‖ ≤ ‖a‖ + ‖b‖. The so-called "L0 norm", the count of nonzero entries, fails the scaling rule and is not a true norm, although the name is common.

The shape of each unit ball

The set of points with norm at most 1 shows each norm's character. In two dimensions the L1 ball is a diamond with corners on the axes. The L2 ball is a disk. The infinity ball is a square with sides parallel to the axes.

The corners of the diamond lie where one coordinate is zero. This is the geometric reason L1 constraints tend to produce sparse solutions.

Three norms and their personalities
L1 Sum of absolute values Diamond-shaped ball Linked to medians and sparsity L2 Straight-line length Round ball Linked to means and smooth shrinkage Infinity Largest absolute entry Square ball Linked to worst-case limits L1 Sum of absolute values Diamond-shaped ball Linked to medians and sparsity L2 Straight-line length Round ball Linked to means and smooth shrinkage Infinity Largest absolute entry Square ball Linked to worst-case limits

How they relate

For any vector in d dimensions, the norms satisfy a chain of inequalities.

‖x‖∞ ≤ ‖x‖₂ ≤ ‖x‖₁
‖x‖₁ ≤ √d · ‖x‖₂
‖x‖₂ ≤ √d · ‖x‖∞

For a vector of d ones, the infinity norm is 1, the L2 norm is √d and the L1 norm is d. For a vector with a single nonzero entry, all three are equal. The ratio between them therefore tells you something about whether size is concentrated in a few entries or spread across many.

Each norm also has a partner, called its dual norm, in bounds on dot products. You have |w · x| ≤ ‖w‖₂ ‖x‖₂, and also |w · x| ≤ ‖w‖₁ ‖x‖∞. The first is explored in dot products and cosine similarity. The second says that if each input can shift by at most ε, a linear score can shift by at most ε‖w‖₁.

Norms in loss functions

Applied to a vector of errors, each norm defines a different notion of a good fit. The clearest case is predicting a single constant c for the values 1, 2, 3, 4 and 100.

What you minimize Best constant c Value here
Sum of absolute errors (L1) Median 3
Sum of squared errors (squared L2) Mean 22
Largest absolute error (infinity) Midpoint of minimum and maximum 50.5

The outlier of 100 barely affects the L1 answer, pulls the L2 answer strongly and controls half of the infinity answer. Mean absolute error and mean squared error, compared in regression scores, inherit this behavior.

A compromise called the Huber loss is quadratic for small errors and linear for large ones. It keeps a smooth gradient near zero while limiting the pull of outliers.

Norms as penalties on weights

Adding a norm of the weights to the loss discourages large values. The two usual choices act very differently. To see why, solve a one-weight problem where the unpenalized best value is a.

L1:  minimize ½(w − a)² + λ|w|
     solution: sign(a) · max(|a| − λ, 0)       soft thresholding

L2:  minimize ½(w − a)² + (λ/2) w²
     solution: a / (1 + λ)                     proportional shrinkage

With λ = 0.5 and two weights whose unpenalized values are 3 and 0.4, L1 gives 2.5 and exactly 0. L2 gives 2 and about 0.267. L1 subtracts a fixed amount and removes whatever is smaller than that amount. L2 divides everything by the same factor, so nothing nonzero reaches zero.

This is the core of lasso and ridge regression. Both depend on feature units, so standardize using training data before applying a shared penalty. The intercept is usually left unpenalized.

In deep learning, "weight decay" is often described as an L2 penalty. The two match for plain gradient descent with a suitable rescaling, but they differ under adaptive optimizers such as Adam, which is why AdamW applies the decay separately.

Norms for clipping gradients

Training sometimes produces a very large gradient that would throw the parameters far away. Two common limits use different norms.

Say the gradient is g = (6, 8) and the limit is 5.

clip by L2 norm:   ‖g‖₂ = 10 > 5, so g · (5/10) = (3, 4)
clip by value:     each entry limited to [−5, 5]  → (5, 5)

Norm clipping rescales the whole vector and preserves its direction. Value clipping enforces an infinity-norm limit and here rotates the step toward the diagonal. In large networks, norm clipping is typically computed over all parameters together. Gradient clipping discusses when it is needed.

Distances, normalization and robustness

Every norm gives a distance: the norm of the difference between two points.

  • L1 or Manhattan distance sums coordinate gaps. It is less dominated by a single large gap than L2.
  • L2 or Euclidean distance is unchanged by rotating the space.
  • Infinity or Chebyshev distance reports only the worst coordinate.

Norms also normalize vectors. Dividing a vector of word counts by its L1 norm turns it into proportions. Dividing an embedding by its L2 norm places it on a unit sphere, so dot products become cosines.

In robustness research, a defender asks whether predictions stay stable when an input changes by at most ε in some norm. An infinity limit allows every pixel to move slightly. An L2 limit constrains the total energy of the change. A model that holds up under one kind of limit may fail under another, and none of them fully captures what a person would consider the same image.

Norms and the number of dimensions

Norms grow with the length of a vector, so raw values are hard to compare across layers or models of different size. A vector of d entries, each of magnitude 0.1, has these norms.

d L1 L2 Infinity
1 0.1 0.1 0.1
100 10 1 0.1
10,000 1,000 10 0.1

To compare typical entry size, divide the L1 norm by d, which gives the mean absolute value, or divide the L2 norm by √d, which gives the root mean square.

This matters when you monitor training. A large layer will usually show a larger gradient norm than a small one simply because it has more entries. The ratio of an update's norm to the weight's norm is often more informative than either alone. Gradient norms and activation statistics shows how to read those traces.

The infinity norm is useful as an alarm. One exploding entry can hide inside an L2 norm over millions of values, but it appears at once in the maximum. Also check for non-finite values directly, since a single NaN makes every one of these sums meaningless.

A robustness budget has the same dependence on size. A shift of ε in every one of d inputs has infinity norm ε but L2 norm ε√d. The two budgets are therefore not interchangeable, and a value of ε quoted without its norm says very little.

Matrix norms

Matrices have norms too. The Frobenius norm treats the matrix as one long vector and takes its L2 norm. The spectral norm is the largest factor by which the matrix can stretch a vector's L2 length, and it equals the largest singular value. The nuclear norm, the sum of singular values, is used to encourage low rank.

In NumPy the defaults differ between vectors and matrices.

import numpy as np

x = np.array([3.0, -4.0, 0.0])
print(np.linalg.norm(x, 1))        # 7.0
print(np.linalg.norm(x))           # 5.0  (L2)
print(np.linalg.norm(x, np.inf))   # 4.0

A = np.diag([3.0, 4.0])
print(np.linalg.norm(A))           # 5.0  (Frobenius)
print(np.linalg.norm(A, 2))        # 4.0  (spectral)

Passing ord=1 to a matrix gives the largest column sum of absolute values, not the sum of all entries. If you want per-row norms of a batch with shape (n, d), pass axis=1.

Common questions

Why is the L2 penalty usually squared?

The squared version has a simple gradient, λw, that goes smoothly to zero. The unsquared L2 norm has no derivative at the origin, which is useful in group lasso, where whole blocks of weights are removed together.

Can I optimize an L1 term with gradient descent?

The absolute value has a kink at zero. Plain subgradient steps tend to hover around zero without landing on it. Soft thresholding, used by proximal methods, produces exact zeros.

Which norm should I report?

Report the one that matches the cost of error in your application. If one large miss is unacceptable, look at the maximum. If total error is what accumulates, an average of absolute errors says it directly.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 26 articles in The Math Behind the Methods →

Latest news on this topic