numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturns
cond(x, p=None)

This function is capable of returning the condition number using one of seven different norms, depending on the value of p (see Parameters below).

Notes

The condition number of x is defined as the norm of x times the norm of the inverse of x ; the norm can be the usual L2-norm (root-of-sum-of-squares) or one of a number of other matrix norms.

Parameters

x : (..., M, N) array_like

The matrix whose condition number is sought.

p : {None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional

Order of the norm used in the condition number computation:

===== ============================ p norm for matrices ===== ============================ None 2-norm, computed directly using the SVD 'fro' Frobenius norm inf max(sum(abs(x), axis=1)) -inf min(sum(abs(x), axis=1)) 1 max(sum(abs(x), axis=0)) -1 min(sum(abs(x), axis=0)) 2 2-norm (largest sing. value) -2 smallest singular value ===== ============================

inf means the numpy.inf object, and the Frobenius norm is the root-of-sum-of-squares norm.

Returns

c : {float, inf}

The condition number of the matrix. May be infinite.

Compute the condition number of a matrix.

See Also

numpy.linalg.norm

Examples

>>> from numpy import linalg as LA
... a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]])
... a array([[ 1, 0, -1], [ 0, 1, 0], [ 1, 0, 1]])
>>> LA.cond(a)
1.4142135623730951
>>> LA.cond(a, 'fro')
3.1622776601683795
>>> LA.cond(a, np.inf)
2.0
>>> LA.cond(a, -np.inf)
1.0
>>> LA.cond(a, 1)
2.0
>>> LA.cond(a, -1)
1.0
>>> LA.cond(a, 2)
1.4142135623730951
>>> LA.cond(a, -2)
0.70710678118654746 # may vary
>>> min(LA.svd(a, compute_uv=False))*min(LA.svd(LA.inv(a), compute_uv=False))
0.70710678118654746 # may vary
See :

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 : /numpy/linalg/linalg.py#1669
type: <class 'function'>
Commit: