bundles / scipy latest / scipy / linalg / _misc / norm
function
scipy.linalg._misc:norm
source: /scipy/linalg/_misc.py :17
Signature
def norm ( a , ord = None , axis = None , keepdims = False , check_finite = True ) Summary
Matrix or vector norm.
Extended Summary
This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the ord parameter. For tensors with rank different from 1 or 2, only ord=None is supported.
Parameters
a: array_likeInput array. If
axisis None,amust be 1-D or 2-D, unlessordis None. If bothaxisandordare None, the 2-norm ofa.ravelwill be returned.ord: {int, inf, -inf, 'fro', 'nuc', None}, optionalOrder of the norm (see table under
Notes). inf means NumPy'sinfobject.axis: {int, 2-tuple of ints, None}, optionalIf
axisis an integer, it specifies the axis ofaalong which to compute the vector norms. Ifaxisis a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed. Ifaxisis None then either a vector norm (whenais 1-D) or a matrix norm (whenais 2-D) is returned.keepdims: bool, optionalIf this is set to True, the axes which are normed over are left in the result as dimensions with size one. With this option the result will broadcast correctly against the original
a.check_finite: bool, optionalWhether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
Returns
n: float or ndarrayNorm of the matrix or vector(s).
Notes
For values of ord <= 0, 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 -- 'nuc' nuclear norm -- inf max(sum(abs(a), axis=1)) max(abs(a)) -inf min(sum(abs(a), axis=1)) min(abs(a)) 0 -- sum(a != 0) 1 max(sum(abs(a), axis=0)) as below -1 min(sum(abs(a), axis=0)) as below 2 2-norm (largest sing. value) as below -2 smallest singular value as below other -- sum(abs(a)**ord)**(1./ord) ===== ============================ ==========================
The Frobenius norm is given by [1]:
The nuclear norm is the sum of the singular values.
Both the Frobenius and nuclear norm orders are only defined for matrices.
Examples
import numpy as np from scipy.linalg import norm a = np.arange(9) - 4.0 a b = a.reshape((3, 3)) b✓
norm(a)
✓norm(b) norm(b, 'fro') norm(a, np.inf)✗
norm(b, np.inf)
✓norm(a, -np.inf) norm(b, -np.inf)✗
norm(a, 1)
✗norm(b, 1)
✓norm(a, -1) norm(b, -1)✗
norm(a, 2)
✓norm(b, 2)
✗norm(a, -2) norm(b, -2) norm(a, 3) norm(a, -3)✗
Aliases
-
scipy.linalg.norm