fn
cond
→Tensorcond(A: Tensor, p: int | float | str | None = None)Compute the condition number of a matrix.
The condition number under norm is
For the spectral () norm this simplifies to the ratio of the largest to smallest singular value:
The condition number quantifies how sensitive the solution of is to perturbations in or .
Parameters
ATensorInput matrix of shape
(*, m, n).p(int, float, str or None)= NoneNorm order.
None (default) and 2 use the spectral
norm via SVD; -2 returns the reciprocal . Other orders dispatch to norm.Returns
TensorCondition number, shape (*,).
Notes
A condition number near
indicates numerical singularity. Non-spectral orders require an
explicit inv, so prefer p = 2 for rank-deficient or
rectangular matrices.
Examples
>>> import lucid
>>> from lucid.linalg import cond
>>> cond(lucid.tensor([[1.0, 0.0], [0.0, 1e-6]]))
Tensor(1000000.0)