fn
vector_norm
→Tensorvector_norm(x: Tensor, ord: int | float = 2, dim: int | list[int] | None = None, keepdim: bool = False, dtype: object = None)Compute a vector -norm along an axis.
Reduces along dim (or all elements if dim is None) using
for any positive real . Special-cased values:
- — count of non-zero entries (not a true norm).
- — .
- — Euclidean norm.
- — .
- — .
Parameters
xTensorInput tensor.
ordint or float= 2Order of the norm. Default
2.dimint, list of int or None= NoneAxis or axes to reduce.
None flattens first.keepdimbool= FalseIf
True, reduced dimensions are retained with size 1.dtypeoptional= NoneCurrently unused; reserved for future accumulation-dtype
control.
Returns
TensorNorm along the specified axes.
Notes
All operations are routed through autograd-aware engine kernels, so gradients flow naturally even for non-integer (via -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)