linalg.svd
Description
Decompose a singular value.
When a is a 2D array, and full_matrices=False, it is factorized as u @ np.diag(s) @ vh = (u * s) @ vh, where u and the Hermitian transpose of vh are 2D arrays with orthonormal columns and s is a 1D array of a's singular values. When a is higher-dimensional, singular value decomposition (SVD) is applied in stacked mode.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
a |
(…,M,N) array_like |
A real or complex array with a.ndim >= 2 |
b |
array_like |
- |
Optional Input Parameters
Parameter |
Type |
Default Value |
Description |
|---|---|---|---|
full_matrices |
bool |
True |
If the default value True is used, u and vh have the shapes (..., M, M) and (..., N, N), respectively. Otherwise, the shapes are (..., M, K) and (..., K, N), respectively, where K = min(M, N). |
compute_uv |
bool |
True |
Whether or not to compute u and vh in addition to s. |
Return Value
Parameter |
Type |
Description |
|---|---|---|
u |
{(…,M,M), (…,M,K)} array |
Unitary array. The first a.ndim-2 dimensions have the same size as those of the input a. The size of the last two dimensions depends on the value of full_matrices. It is only returned when compute_uv is True. |
s |
(…, K) array |
Vectors with singular values, within each vector sorted in descending order. The first a.ndim-2 dimensions have the same size as those of the input a. |
vh |
{(…,N,N), (…,K,N)} array |
Unitary array. The first a.ndim-2 dimensions have the same size as those of the input a. The size of the last two dimensions depends on the value of full_matrices. It is only returned when compute_uv is True. |
Examples
>>> import numpy as np >>> a = np.random.randn(9, 6) + 1j * np.random.randn(9, 6) >>> b = np.random.randn(2, 7, 8, 3) + 1j * np.random.randn(2, 7, 8, 3) >>> >>> u, s, vh = np.linalg.svd(a, full_matrices=True) >>> u.shape, s.shape, vh.shape ((9, 9), (6,), (6, 6)) >>> np.allclose(a, np.dot(u[:, :6] * s, vh)) True >>> >>> smat = np.zeros((9,6), dtype=complex) >>> smat[:6, :6] = np.diag(s) >>> np.allclose(a, np.dot(u, np.dot(smat, vh))) True >>>