python numpy实现SVD 矩阵分解

linalg.svd(afull_matrices=Truecompute_uv=Truehermitian=False)

Examples

>>> 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)

Reconstruction based on full SVD, 2D case:

>>> 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

 

 

参考:https://numpy.org/doc/stable/reference/generated/numpy.linalg.svd.html

 

posted @ 2021-11-11 16:31  StarZhai  阅读(706)  评论(0)    收藏  举报