scipy.linalg.svd(a, full_matrices=True, compute_uv=True, overwrite_a=False)

Singular Value Decomposition.

Factorizes the matrix a into two unitary matrices U and Vh and an 1d-array s of singular values (real, non-negative) such that a == U S Vh if S is an suitably shaped matrix of zeros whose main diagonal is s.

Parameters :

a : array, shape (M, N)

Matrix to decompose

full_matrices : boolean

If true, U, Vh are shaped (M,M), (N,N) If false, the shapes are (M,K), (K,N) where K = min(M,N)

compute_uv : boolean

Whether to compute also U, Vh in addition to s (Default: true)

overwrite_a : boolean

Whether data in a is overwritten (may improve performance)

Returns :

U: array, shape (M,M) or (M,K) depending on full_matrices :

s: array, shape (K,) :

The singular values, sorted so that s[i] >= s[i+1]. K = min(M, N)

Vh: array, shape (N,N) or (K,N) depending on full_matrices :

For compute_uv = False, only s is returned. :

Raises LinAlgError if SVD computation does not converge :

See also

return singular values of a matrix
return the Sigma matrix, given the vector s


>>> from scipy import random, linalg, allclose, dot
>>> a = random.randn(9, 6) + 1j*random.randn(9, 6)
>>> U, s, Vh = linalg.svd(a)
>>> U.shape, Vh.shape, s.shape
((9, 9), (6, 6), (6,))
>>> U, s, Vh = linalg.svd(a, full_matrices=False)
>>> U.shape, Vh.shape, s.shape
((9, 6), (6, 6), (6,))
>>> S = linalg.diagsvd(s, 6, 6)
>>> allclose(a, dot(U, dot(S, Vh)))
>>> s2 = linalg.svd(a, compute_uv=False)
>>> allclose(s, s2)

Previous topic


Next topic


This Page