fn
matrix_norm
→Tensormatrix_norm(x: Tensor, ord: int | float | str = 'fro', dim: tuple[int, int] = (-2, -1), keepdim: bool = False)Compute a matrix norm.
Reduces the trailing two axes of an input to a scalar matrix norm. Supported orders:
"fro"— Frobenius norm ."nuc"— nuclear norm (sum of singular values).1/-1— max / min absolute column sum.inf/-inf— max / min absolute row sum.2/-2— largest / smallest singular value (spectral norm and its reciprocal).
Parameters
xTensorInput of shape
(*, m, n).ord(int, float or str)= 'fro'Norm order. Default
"fro".dimtuple of two ints= (-2, -1)Axis pair identifying the matrix dimensions. Default
(-2, -1).keepdimbool= FalseIf
True, reduced dims are retained with size 1.Returns
TensorMatrix norm of each batch.
Notes
Spectral and nuclear norms require an SVD and so cost . Entry-wise norms reduce in a single pass.
Examples
>>> import lucid
>>> from lucid.linalg import matrix_norm
>>> A = lucid.tensor([[3.0, 4.0], [0.0, 0.0]])
>>> matrix_norm(A, ord="fro")
Tensor(5.0)