cond#
- rlinalg.cond(a: numpy.typing.ArrayLike, overwrite_a: bool = False, exact: bool = False, norm: Union[Literal[1], Literal[2], Literal[numpy.inf], None] = None, method: Union[Literal['qr'], Literal['raw']] = 'qr', check_finite: bool = True, lower: bool = False) float#
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=Truerequiresnorm=Noneornorm=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
ais 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
dqrdc2anddtrco.When
exact=False, this function uses a QR decomposition rather than a SVD decomposition in the case ofnumpy.linalg.cond. This is the same behaviour as the R functionkappa.See also
numpy.linalg.condThe 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...
References
Anderson., E., et al. (1999) LAPACK Users’ Guide. Third Edition. SIAM. Available on-line at https://netlib.org/lapack/lug/lapack_lug.html.
Chambers, J. M. (1992) Linear models. Chapter 4 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Dongarra, J. J., Bunch, J. R., Moler, C. B. and Stewart, G. W. (1978) LINPACK Users Guide. Philadelphia: SIAM Publications.