Vector Norms

Copyright (C) 2020 Andreas Kloeckner

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Computing norms by hand

$p$-norms can be computed in two different ways in numpy:

First, let's compute the 2-norm by hand:

Next, let's use numpy machinery to compute it:

Both of the values above represent the 2-norm: $\|x\|_2$.


About the $\infty$-norm

Different values of $p$ work similarly:


The $\infty$ norm represents a special case, because it's actually (in some sense) the limit of $p$-norms as $p\to\infty$.

Recall that: $\|x\|_\infty = \max(|x_1|, |x_2|, |x_3|)$.

Where does that come from? Let's try with $p=100$:

Compare to last value in vector: the addition has essentially taken the maximum:

Numpy can compute that, too:


Unit Balls

Once you know the set of vectors for which $\|x\|=1$, you know everything about the norm, because of semilinearity. The graphical version of this is called the 'unit ball'.

We'll make a bunch of vectors in 2D (for visualization) and then scale them so that $\|x\|=1$.