Singular Value Decomposition.
Factorizes the matrix a into two unitary matrices, U and Vh, and a 1-dimensional array of singular values, s (real, non-negative), such that a == U S Vh, where S is the diagonal matrix np.diag(s).
Parameters: | a : array_like, shape (M, N)
full_matrices : boolean, optional
compute_uv : boolean
|
---|---|
Returns: | U : ndarray, shape (M, M) or (M, K) depending on full_matrices
s : ndarray, shape (K,) where K = min(M, N)
Vh : ndarray, shape (N,N) or (K,N) depending on full_matrices
|
Raises: | LinAlgError :
|
Notes
If a is a matrix (in contrast to an ndarray), then so are all the return values.
Examples
>>> a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6)
>>> U, s, Vh = np.linalg.svd(a)
>>> U.shape, Vh.shape, s.shape
((9, 9), (6, 6), (6,))
>>> U, s, Vh = np.linalg.svd(a, full_matrices=False)
>>> U.shape, Vh.shape, s.shape
((9, 6), (6, 6), (6,))
>>> S = np.diag(s)
>>> np.allclose(a, np.dot(U, np.dot(S, Vh)))
True
>>> s2 = np.linalg.svd(a, compute_uv=False)
>>> np.allclose(s, s2)
True