dpnp.linalg.cond

dpnp.linalg.cond(x, p=None)[source]

Compute the condition number of a matrix.

For full documentation refer to numpy.linalg.cond.

Parameters:
x{dpnp.ndarray, usm_ndarray}

The matrix whose condition number is sought.

p{None, 1, -1, 2, -2, inf, -inf, "fro"}, optional

Order of the norm used in the condition number computation:

p

norm for matrices

None

2-norm

'fro'

Frobenius norm

inf

max(sum(abs(x), axis=1))

-inf

min(sum(abs(x), axis=1))

1

max(sum(abs(x), axis=0))

-1

min(sum(abs(x), axis=0))

2

2-norm (largest singular value)

-2

smallest singular value

inf means the dpnp.inf object, and the Frobenius norm is the root-of-sum-of-squares norm.

Default: None.

Returns:
outdpnp.ndarray

The condition number of the matrix. May be infinite.

See also

dpnp.linalg.norm

Matrix or vector norm.

Notes

This function will raise dpnp.linalg.LinAlgError on singular input when using any of the norm: 1, -1, inf, -inf, or 'fro'. In contrast, numpy.linalg.cond will fill the result array with inf values for each 2D batch in the input array that is singular when using these norms.

Examples

>>> import dpnp as np
>>> a = np.array([[1, 0, -1], [0, 1, 0], [1, 0, 1]])
>>> a
array([[ 1,  0, -1],
       [ 0,  1,  0],
       [ 1,  0,  1]])
>>> np.linalg.cond(a)
array(1.41421356)
>>> np.linalg.cond(a, 'fro')
array(3.16227766)
>>> np.linalg.cond(a, np.inf)
array(2.)
>>> np.linalg.cond(a, -np.inf)
array(1.)
>>> np.linalg.cond(a, 1)
array(2.)
>>> np.linalg.cond(a, -1)
array(1.)
>>> np.linalg.cond(a, 2)
array(1.41421356)
>>> np.linalg.cond(a, -2)
array(0.70710678) # may vary
>>> x = min(np.linalg.svd(a, compute_uv=False))
>>> y = min(np.linalg.svd(np.linalg.inv(a), compute_uv=False))
>>> x * y
array(0.70710678) # may vary