- 
numpy.linalg.svd(a, full_matrices=1, compute_uv=1)[source] - 
Singular Value Decomposition.
Factors the matrix
aasu * np.diag(s) * v, whereuandvare unitary andsis a 1-d array ofa?s singular values.Parameters: a : (..., M, N) array_like
A real or complex matrix of shape (
M,N) .full_matrices : bool, optional
If True (default),
uandvhave the shapes (M,M) and (N,N), respectively. Otherwise, the shapes are (M,K) and (K,N), respectively, whereK= min(M,N).compute_uv : bool, optional
Whether or not to compute
uandvin addition tos. True by default.Returns: u : { (..., M, M), (..., M, K) } array
Unitary matrices. The actual shape depends on the value of
full_matrices. Only returned whencompute_uvis True.s : (..., K) array
The singular values for every matrix, sorted in descending order.
v : { (..., N, N), (..., K, N) } array
Unitary matrices. The actual shape depends on the value of
full_matrices. Only returned whencompute_uvis True.Raises: LinAlgError
If SVD computation does not converge.
Notes
New in version 1.8.0.
Broadcasting rules apply, see the
numpy.linalgdocumentation for details.The decomposition is performed using LAPACK routine _gesdd
The SVD is commonly written as
a = U S V.H. Thevreturned by this function isV.Handu = U.If
Uis a unitary matrix, it means that it satisfiesU.H = inv(U).The rows of
vare the eigenvectors ofa.H a. The columns ofuare the eigenvectors ofa a.H. For rowiinvand columniinu, the corresponding eigenvalue iss[i]**2.If
ais amatrixobject (as opposed to anndarray), then so are all the return values.Examples
>>> a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6)
Reconstruction based on full SVD:
>>> U, s, V = np.linalg.svd(a, full_matrices=True) >>> U.shape, V.shape, s.shape ((9, 9), (6, 6), (6,)) >>> S = np.zeros((9, 6), dtype=complex) >>> S[:6, :6] = np.diag(s) >>> np.allclose(a, np.dot(U, np.dot(S, V))) True
Reconstruction based on reduced SVD:
>>> U, s, V = np.linalg.svd(a, full_matrices=False) >>> U.shape, V.shape, s.shape ((9, 6), (6, 6), (6,)) >>> S = np.diag(s) >>> np.allclose(a, np.dot(U, np.dot(S, V))) True
 
numpy.linalg.svd()
2025-01-10 15:47:30
            
          
Please login to continue.