MCPcopy Create free account
hub / github.com/numpy/numpy / cond

Function cond

numpy/linalg/linalg.py:1703–1818  ·  view source on GitHub ↗

Compute the condition number of a matrix. This function is capable of returning the condition number using one of seven different norms, depending on the value of `p` (see Parameters below). Parameters ---------- x : (..., M, N) array_like The matrix whose cond

(x, p=None)

Source from the content-addressed store, hash-verified

1701
1702@array_function_dispatch(_cond_dispatcher)
1703def cond(x, p=None):
1704 """
1705 Compute the condition number of a matrix.
1706
1707 This function is capable of returning the condition number using
1708 one of seven different norms, depending on the value of `p` (see
1709 Parameters below).
1710
1711 Parameters
1712 ----------
1713 x : (..., M, N) array_like
1714 The matrix whose condition number is sought.
1715 p : {None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional
1716 Order of the norm used in the condition number computation:
1717
1718 ===== ============================
1719 p norm for matrices
1720 ===== ============================
1721 None 2-norm, computed directly using the ``SVD``
1722 'fro' Frobenius norm
1723 inf max(sum(abs(x), axis=1))
1724 -inf min(sum(abs(x), axis=1))
1725 1 max(sum(abs(x), axis=0))
1726 -1 min(sum(abs(x), axis=0))
1727 2 2-norm (largest sing. value)
1728 -2 smallest singular value
1729 ===== ============================
1730
1731 inf means the `numpy.inf` object, and the Frobenius norm is
1732 the root-of-sum-of-squares norm.
1733
1734 Returns
1735 -------
1736 c : {float, inf}
1737 The condition number of the matrix. May be infinite.
1738
1739 See Also
1740 --------
1741 numpy.linalg.norm
1742
1743 Notes
1744 -----
1745 The condition number of `x` is defined as the norm of `x` times the
1746 norm of the inverse of `x` [1]_; the norm can be the usual L2-norm
1747 (root-of-sum-of-squares) or one of a number of other matrix norms.
1748
1749 References
1750 ----------
1751 .. [1] G. Strang, *Linear Algebra and Its Applications*, Orlando, FL,
1752 Academic Press, Inc., 1980, pg. 285.
1753
1754 Examples
1755 --------
1756 >>> from numpy import linalg as LA
1757 >>> a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]])
1758 >>> a
1759 array([[ 1, 0, -1],
1760 [ 0, 1, 0],

Callers

nothing calls this directly

Calls 13

asarrayFunction · 0.90
errstateClass · 0.90
_is_empty_2dFunction · 0.85
LinAlgErrorClass · 0.85
_assert_stacked_2dFunction · 0.85
_assert_stacked_squareFunction · 0.85
_commonTypeFunction · 0.85
isComplexTypeFunction · 0.85
normFunction · 0.85
isnanFunction · 0.85
astypeMethod · 0.80
svdFunction · 0.70

Tested by

no test coverage detected