MCPcopy
hub / github.com/numpy/numpy / cond

Function cond

numpy/linalg/_linalg.py:1914–2027  ·  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

1912
1913@array_function_dispatch(_cond_dispatcher)
1914def cond(x, p=None):
1915 """
1916 Compute the condition number of a matrix.
1917
1918 This function is capable of returning the condition number using
1919 one of seven different norms, depending on the value of `p` (see
1920 Parameters below).
1921
1922 Parameters
1923 ----------
1924 x : (..., M, N) array_like
1925 The matrix whose condition number is sought.
1926 p : {None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional
1927 Order of the norm used in the condition number computation:
1928
1929 ===== ============================
1930 p norm for matrices
1931 ===== ============================
1932 None 2-norm, computed directly using the ``SVD``
1933 'fro' Frobenius norm
1934 inf max(sum(abs(x), axis=1))
1935 -inf min(sum(abs(x), axis=1))
1936 1 max(sum(abs(x), axis=0))
1937 -1 min(sum(abs(x), axis=0))
1938 2 2-norm (largest sing. value)
1939 -2 smallest singular value
1940 ===== ============================
1941
1942 inf means the `numpy.inf` object, and the Frobenius norm is
1943 the root-of-sum-of-squares norm.
1944
1945 Returns
1946 -------
1947 c : {float, inf}
1948 The condition number of the matrix. May be infinite.
1949
1950 See Also
1951 --------
1952 numpy.linalg.norm
1953
1954 Notes
1955 -----
1956 The condition number of `x` is defined as the norm of `x` times the
1957 norm of the inverse of `x` [1]_; the norm can be the usual L2-norm
1958 (root-of-sum-of-squares) or one of a number of other matrix norms.
1959
1960 References
1961 ----------
1962 .. [1] G. Strang, *Linear Algebra and Its Applications*, Orlando, FL,
1963 Academic Press, Inc., 1980, pg. 285.
1964
1965 Examples
1966 --------
1967 >>> import numpy as np
1968 >>> from numpy import linalg as LA
1969 >>> a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]])
1970 >>> a
1971 array([[ 1, 0, -1],

Callers

nothing calls this directly

Calls 12

asarrayFunction · 0.90
errstateClass · 0.90
_is_empty_2dFunction · 0.85
LinAlgErrorClass · 0.85
svdFunction · 0.85
_assert_stacked_squareFunction · 0.85
_commonTypeFunction · 0.85
_realTypeFunction · 0.85
isComplexTypeFunction · 0.85
normFunction · 0.85
astypeMethod · 0.80
anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…