fn
norm
→Tensornorm(x: Tensor, ord: int | float | str | None = None, dim: int | list[int] | None = None, keepdim: bool = False)Compute a vector or matrix norm.
Generic norm dispatcher that delegates to vector_norm or
matrix_norm based on the input rank and reduction axes.
The default behaviour computes the Frobenius norm of a matrix input
and the Euclidean () norm of a vector input:
Parameters
xTensorInput tensor. May be a vector
(n,), a matrix (m, n), or
higher-rank with explicit dim.ord(int, float, str or None)= NoneOrder of the norm. Vector orders:
0, 1, 2 (default
when None), inf, -inf, or any positive real. Matrix
orders: "fro", "nuc", 1, -1, 2, -2,
inf, -inf.dimint, list of int or None= NoneReduction axis (or pair of axes for matrix norms).
None
reduces over all elements.keepdimbool= FalseIf
True, retains reduced dimensions with size 1.Returns
TensorNorm value(s); shape depends on dim / keepdim.
Notes
Many norm orders (spectral, nuclear) require an SVD and therefore cost ; entry-wise norms reduce in a single pass.
Examples
>>> import lucid
>>> from lucid.linalg import norm
>>> norm(lucid.tensor([3.0, 4.0]))
Tensor(5.0)