norm¶
-
norm(x, ord=None, axis=None, keepdims=False)¶ Matrix or vector norm.
This function can only support Frobenius norm for now. The Frobenius norm is given by [1]:
\(||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}\)Parameters: - x : ndarray
Input array.
- ord : {‘fro’}, optional
Order of the norm.
- axis : {int, 2-tuple of ints, None}, optional
If axis is an integer, it specifies the axis of x along which to compute the vector norms. If axis is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed. If axis is None, the norm of the whole ndarray is returned.
- keepdims : bool, optional
If 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 x.
Returns: - n : float or ndarray
Norm of the matrix or vector(s).
Notes
This operator differs from NumPy in the aspect that it always returns a zero-dim tensor for the cases where Python float values are expected in NumPy.
References
[1] G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 Examples
>>> from numpy import linalg as LA >>> a = np.arange(9) - 4 >>> a array([-4., -3., -2., -1., 0., 1., 2., 3., 4.]) >>> b = a.reshape((3, 3)) >>> b array([[-4., -3., -2.], [-1., 0., 1.], [ 2., 3., 4.]]) >>> LA.norm(a) array(7.745967) >>> >>> LA.norm(b) array(7.745967) >>> LA.norm(b, 'fro') array(7.745967)