fn

vector_norm

Tensor
vector_norm(x: Tensor, ord: int | float = 2, dim: int | list[int] | None = None, keepdim: bool = False, dtype: object = None)
source

Compute a vector pp-norm along an axis.

Reduces along dim (or all elements if dim is None) using

xp=(ixip)1/p\|x\|_p \,=\, \Big(\sum_i |x_i|^{\,p}\Big)^{1/p}

for any positive real pp. Special-cased values:

  • p=0p = 0 — count of non-zero entries (not a true norm).
  • p=1p = 1ixi\sum_i |x_i|.
  • p=2p = 2 — Euclidean norm.
  • p=+p = +\inftymaxixi\max_i |x_i|.
  • p=p = -\inftyminixi\min_i |x_i|.

Parameters

xTensor
Input tensor.
ordint or float= 2
Order of the norm. Default 2.
dimint, list of int or None= None
Axis or axes to reduce. None flattens first.
keepdimbool= False
If True, reduced dimensions are retained with size 1.
dtypeoptional= None
Currently unused; reserved for future accumulation-dtype control.

Returns

Tensor

Norm along the specified axes.

Notes

All operations are routed through autograd-aware engine kernels, so gradients flow naturally even for non-integer pp (via pp-power and root).

Examples

>>> import lucid
>>> from lucid.linalg import vector_norm
>>> vector_norm(lucid.tensor([3.0, 4.0]))
Tensor(5.0)
>>> vector_norm(lucid.tensor([1.0, -2.0, 3.0]), ord=1)
Tensor(6.0)