flopscope.

flopscope.numpy.linalg.svdvals

fnp.linalg.svdvals(x: 'ArrayLike', /, *, k: 'int | None' = None) -> 'FlopscopeArray'[flopscope source][numpy source]

Returns the singular values of a matrix (or a stack of matrices) ``x``. When x is a stack of matrices, the function will compute the singular values for each matrix in the stack.

Adapted from NumPy docs np.linalg.svdvals

Arealinalg
Typecustom
Cost
mnmin(m,n)m \cdot n \cdot \min(m,n)
Flopscope Context

Singular values only. Cost: m*n*min(m,n) (Golub-Reinsch).

Returns the singular values of a matrix (or a stack of matrices) x. When x is a stack of matrices, the function will compute the singular values for each matrix in the stack.

This function is Array API compatible.

Calling flops.svdvals(x) to get singular values is the same as flops.svd(x, compute_uv=False, hermitian=False).

Parameters

x:(..., M, N) array_like

Input array having shape (..., M, N) and whose last two dimensions form matrices on which to perform singular value decomposition. Should have a floating-point data type.

Returns

out:ndarray

An array with shape (..., K) that contains the vector(s) of singular values of length K, where K = min(M, N).

See also

Examples

>>> flops.linalg.svdvals([[1, 2, 3, 4, 5],
... [1, 4, 9, 16, 25],
... [1, 8, 27, 64, 125]])
array([146.68862757,   5.57510612,   0.60393245])

Determine the rank of a matrix using singular values:

>>> s = flops.linalg.svdvals([[1, 2, 3],
... [2, 4, 6],
... [-1, 1, -1]]); s
array([8.38434191e+00, 1.64402274e+00, 2.31534378e-16])
>>> flops.count_nonzero(s > 1e-10)  # Matrix of rank 2
2