< Back

Env

import torch

Nature

\( f(a\mathbf{x}) = |a|f(\mathbf{x}) \)
\( f(\mathbf{x} + \mathbf{y}) \leq f(\mathbf{x}) + f(\mathbf{y}) \)
\( f(\mathbf{x}) \geq 0 \)
\( f(\mathbf{x}) = 0 \iff \mathbf{x} = \mathbf{0} \)


L2
\(\|\mathbf{x}\|_2 = \|\mathbf{x}\| = \sqrt{\sum_{i=1}^n x_i^2} \)

u = torch.tensor([3.0, -4.0])
torch.norm(u)
tensor(5.)


L1
\(\|\mathbf{x}\|_1 = \sum_{i=1}^n |x_i| \)

u = torch.tensor([3.0, -4.0])
torch.abs(u).sum()
tensor(7.)


Lp Generalized
\(\|\mathbf{x}\|_p = \left(\sum_{i=1}^n |x_i|^p\right)^{1/p} \)




Frobenius
\(\|\mathbf{x}\|_F = \left(\sum_{i=1}^n |x_i|^2\right)^{1/2} \)

F = torch.arange(12, dtype = torch.float32).reshape(3,4)
torch.norm(F)
tensor(22.4944)