cond#

rlinalg.cond(a, overwrite_a=False, exact=False, norm=None, method='qr', check_finite=True, lower=False)#

Compute or estimate the condition number of a matrix.

Parameters:
  • a ((M, N) array_like) – Matrix to compute the condition number for

  • exact (bool, optional) – Whether to compute an exact result, or an approximation. exact=True requires norm=None or norm=2.

  • norm ({None, 1, 2, inf}, optional) – Order of the norm used in the condition number computation:

  • method ({'qr', 'raw'}, optional) – Determines whether the input matrix should be first decomposed using QR decomposition (‘qr’), or if the given matrix is already triangular (‘raw’).

  • check_finite (bool, optional) – Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.

  • lower (bool, optional) – Whether a is a lower or upper triangular matrix when running in ‘raw’ mode. Ignored in ‘qr’ mode.

Returns:

kappa (float) – The condition number, or an approximation if exact=False.

Raises:

ValueError – When parameters are not compatible.

Notes

This is an interface to the R-modified LINPACK routine dqrdc2 and dtrco.

When exact=False, this function uses a QR decomposition rather than a SVD decomposition in the case of numpy.linalg.cond. This is the same behaviour as the R function kappa.

See also

numpy.linalg.cond

The NumPy implementation using an SVD decomposition.

kappa

Documentation of the equivalent R function kappa.

Examples

>>> import numpy
>>> import rlinalg
>>> a = numpy.stack([numpy.ones(10), numpy.arange(1, 11)])
>>> rlinalg.cond(a)
15.7059...
>>> rlinalg.cond(a, exact=True)
13.6790...
>>> float(numpy.linalg.cond(a))
13.6790...