scipy.sparse.linalg.norm(x, ord=None, axis=None)[source]

Norm of a sparse matrix

This function is able to return one of seven different matrix norms, depending on the value of the ord parameter.


x : a sparse matrix

Input sparse matrix.

ord : {non-zero int, inf, -inf, ‘fro’}, optional

Order of the norm (see table under Notes). inf means numpy’s inf object.

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 then either a vector norm (when x is 1-D) or a matrix norm (when x is 2-D) is returned.


n : float or ndarray


Some of the ord are not implemented because some associated functions like, _multi_svd_norm, are not yet available for sparse matrix.

This docstring is modified based on numpy.linalg.norm.

The following norms can be calculated:

ord norm for sparse matrices
None Frobenius norm
‘fro’ Frobenius norm
inf max(sum(abs(x), axis=1))
-inf min(sum(abs(x), axis=1))
0 abs(x).sum(axis=axis)
1 max(sum(abs(x), axis=0))
-1 min(sum(abs(x), axis=0))
2 Not implemented
-2 Not implemented
other Not implemented

The Frobenius norm is given by [R302]:

\(||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}\)


[R302](1, 2) G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15


>>> from scipy.sparse import *
>>> import numpy as np
>>> from scipy.sparse.linalg import norm
>>> 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]])
>>> b = csr_matrix(b)
>>> norm(b)
>>> norm(b, 'fro')
>>> norm(b, np.inf)
>>> norm(b, -np.inf)
>>> norm(b, 1)
>>> norm(b, -1)