Singular Value Decomposition.
Factorizes the matrix a into two unitary matrices U and Vh, and a 1-D array s of singular values (real, non-negative) such that a == U*S*Vh, where S is a suitably shaped matrix of zeros with main diagonal s.
Parameters : | a : (M, N) array_like
full_matrices : bool, optional
compute_uv : bool, optional
overwrite_a : bool, optional
check_finite : boolean, optional
|
---|---|
Returns : | U : ndarray
s : ndarray
Vh : ndarray
For ``compute_uv = False``, only `s` is returned. : |
Raises : | LinAlgError :
|
See also
Examples
>>> from scipy import linalg
>>> a = np.random.randn(9, 6) + 1.j*np.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)
>>> np.allclose(a, np.dot(U, np.dot(S, Vh)))
True
>>> s2 = linalg.svd(a, compute_uv=False)
>>> np.allclose(s, s2)
True