cond#
- class saiunit.linalg.cond(x, p=None, **kwargs)#
Compute the condition number of a matrix.
SaiUnit implementation of
numpy.linalg.cond().The condition number is defined as
norm(x, p) * norm(inv(x), p). Forp = 2(the default), the condition number is the ratio of the largest to the smallest singular value. The unit is stripped before computation and the result is a dimensionless JAX array.- Parameters:
x (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – Input of shape(..., M, N)for which to compute the condition number. If x carries a unit, the unit is removed before the computation.p ({None, 1, -1, 2, -2, inf, -inf, 'fro'}, optional) – Order of the norm used in the condition number computation; see
jax.numpy.linalg.norm(). The defaultp = Noneis equivalent top = 2. If p is not in{None, 2, -2}, then x must be square (M = N).
- Returns:
out – Condition number(s) of shape
x.shape[:-2]. Always dimensionless.- Return type:
Array
See also
saiunit.linalg.matrix_rankRank of a matrix via SVD.
saiunit.linalg.slogdetSign and log-determinant of a matrix.
Notes
The condition number is a scalar measure of how sensitive a matrix inversion is to numerical errors. A large condition number indicates an ill-conditioned (nearly singular) matrix.
Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> x = jnp.array([[1., 2.], ... [2., 1.]]) * u.meter >>> u.linalg.cond(x) Array(3., dtype=float32)
Ill-conditioned (rank-deficient) matrix:
>>> import saiunit as u >>> import jax.numpy as jnp >>> x = jnp.array([[1., 2.], ... [0., 0.]]) * u.meter >>> u.linalg.cond(x) Array(inf, dtype=float32)