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}\)

  • 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.


n – Norm of the matrix or vector(s).

Return type

float or ndarray


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.



G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15


>>> 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)
>>> LA.norm(b)
>>> LA.norm(b, 'fro')