您的位置:首页 > 编程语言 > Python开发

Scipy SVD

2016-06-04 09:30 453 查看


scipy.linalg.svd

原文链接:http://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.svd.html

scipy.linalg.svd(a, full_matrices=True, compute_uv=True, overwrite_a=False, check_finite=True)[source]
# 奇异值分解
# 将矩阵分解为两个酉矩阵和一个1维奇异值向量
# E.g. a == U*S*Vh
# 参数选择:
# a : (M, N) 待分解矩阵
# full_matrices : bool型变量, 为可选参数 if true 分解出的U Vh矩阵为方阵 if false 矩阵维度为 (M,K) 与 (K,N), K = min(M,N).
# compute_uv : bool型变量, 为可选参数 在计算出s 同时是否也计算出U 和 Vh if false 只返回s
# overwrite_a: bool型变量, 为可选参数 是否覆写矩阵a来提升性能
# check_finite: bool型变量, 为可选参数 是否检查输入矩阵只包含数值有限的数据 禁用会有性能提升 但是可能导致未知的错误
# 返回值:
# U: 列为左奇异向量的矩阵 维度取决于full_matrices参数 (M,M) or (M,K)
# Vh: 同理 (N,N) or (K,N)
# S: 非升序 奇异值向量 K个元素 K = min(M, N).
# ERROR:
# SVD计算未收敛

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  scipy python