scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
norm(x, ord=None, axis=None)

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

Notes

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. https://github.com/numpy/numpy/blob/master/numpy/linalg/linalg.py

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 :

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

Parameters

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 :None:None:`inf` object.

axis : {int, 2-tuple of ints, None}, optional

If :None:None:`axis` is an integer, it specifies the axis of x along which to compute the vector norms. If :None:None:`axis` is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed. If :None:None:`axis` is None then either a vector norm (when x is 1-D) or a matrix norm (when x is 2-D) is returned.

Returns

n : float or ndarray

Norm of a sparse matrix

Examples

>>> 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) 7.745966692414834
>>> norm(b, 'fro')
7.745966692414834
>>> norm(b, np.inf)
9
>>> norm(b, -np.inf)
2
>>> norm(b, 1)
7
>>> norm(b, -1)
6
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.sparse.linalg._norm.norm

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/sparse/linalg/_norm.py#20
type: <class 'function'>
Commit: