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)
full_matrices : boolean
compute_uv : boolean
overwrite_a : boolean
|
---|---|
Returns: | U: array, shape (M,M) or (M,K) depending on full_matrices : s: array, shape (K,) :
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
Examples
>>> 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)))
True
>>> s2 = linalg.svd(a, compute_uv=False)
>>> allclose(s, s2)
True