torch.linalg.matrix_norm
- torch.linalg.matrix_norm(A, ord='fro', dim=(-2, -1), keepdim=False, *, dtype=None, out
Computes a matrix norm.
If A is complex valued, it computes the norm of A.abs()
Support input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices: the norm will be computed over the
dimensions specified by the 2-tuple dim and the other dimensions will
be treated as batch dimensions. The output will have the same batch dimensions.
ord defines the matrix norm that is computed. The following norms are supported:
| matrix norm |
|---|---|
‘fro’ (default) | Frobenius norm |
‘nuc’ | nuclear norm |
inf | max(sum(abs(x), dim=1)) |
-inf | min(sum(abs(x), dim=1)) |
1 | max(sum(abs(x), dim=0)) |
-1 | min(sum(abs(x), dim=0)) |
2 | largest singular value |
-2 | smallest singular value |
where inf refers to float(‘inf’), NumPy’s inf object, or any equivalent object.
A (Tensor) – tensor with two or more dimensions. By default its
shape is interpreted as (*, m, n) where * is zero or more
batch dimensions, but this behavior can be controlled using dim.
ord (int, inf, -inf, 'fro', 'nuc', optional) – order of norm. Default: ‘fro’
dim (Tuple[int, int) – dimensions over which to compute the norm. Default:
Examples:
>>> from torch import linalg as LA
>>> A = torch.arange(9, dtype=torch.float).reshape(3, 3)
>>> A
tensor([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]])
keepdim (bool, optional) – If set to True, the reduced dimensions are retained in the result as dimensions with size one. Default: False
out (Tensor, optional) – output tensor. Ignored if None. Default: None.
dtype (torch.dtype, optional) – If specified x is cast to
dtype prior to doing the accumulation. Default: None
A real-valued tensor, even when A is complex.