pub fn norm<'a>(
array: impl AsRef<Array>,
ord: impl IntoOption<Ord<'a>>,
axes: impl IntoOption<&'a [i32]>,
keep_dims: impl Into<Option<bool>>,
) -> Result<Array>
Expand description
Matrix or vector norm.
For values of ord < 1
, the result is, strictly speaking, not a
mathematical norm, but it may still be useful for various numerical
purposes.
The following norms can be calculated:
ord | norm for matrices | norm for vectors |
---|---|---|
None | Frobenius norm | 2-norm |
‘fro’ | Frobenius norm | – |
inf | max(sum(abs(x), axis-1)) | max(abs(x)) |
-inf | min(sum(abs(x), axis-1)) | min(abs(x)) |
0 | – | sum(x !- 0) |
1 | max(sum(abs(x), axis-0)) | as below |
-1 | min(sum(abs(x), axis-0)) | as below |
2 | 2-norm (largest sing. value) | as below |
-2 | smallest singular value | as below |
other | – | sum(abs(x)ord)(1./ord) |
Nuclear norm and norms based on singular values are not yet implemented.
The Frobenius norm is given by G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15
The nuclear norm is the sum of the singular values.
Both the Frobenius and nuclear norm orders are only defined for
matrices and produce a fatal error when array.ndim != 2
§Params
array
: input arrayord
: order of the norm, see tableaxes
: axes that hold 2d matriceskeep_dims
: iftrue
the axes which are normed over are left in the result as dimensions with size one