python - scipy.linalg.svd : shapes of VT and U: what is full_matrices and why is it needed?

标签 python scipy svd

scipy.linalg.svd将“任意”数组 A 分解为 U、s、VT 一个例子是:

from numpy import array
from scipy.linalg import svd
import numpy as np

# define a matrix
A = np.arange(200).reshape((100,2))
print ('A.shape',A.shape)
U, s, VT = svd(A)
print ('U.shape',U.shape)
print ('s.shape',s.shape)
print ('VT.shape',VT.shape)
s_diag = np.zeros((100,2))
np.fill_diagonal(s_diag, s) 
print(np.allclose(A,np.dot(np.dot(U,s_diag),VT)))

enter image description here .png

A.shape == (m,n)时,数组U和VT的默认形状为and (m,m)和(n,n)。我注意到有一个选项(full_matrices)符合我的期望,例如: enter image description here 我无法理解的是为什么 U 和 VT 需要是 (m,m) 和 (n,n)? 相乘时,由于 s_diag 是“对角线”,因此 U 和 VT 的唯一部分无论如何,使用的 VT 表都较小...(例如,在示例中,U 的大小可能只是 100,2...)

最佳答案

经过一些wikipedia reading和一些数学内存,事实证明这是有充分理由的......

因此,第一个明显的原因是,根据 m 或 n 中较小的一个,其中一个表无论如何都需要填满。

现在数学原因是在数学理论中 U 和 VT 都是 orthonormal ,这意味着 np.dot(U,U.T) 等于 np.dot(U.T,U) 等于单位矩阵。 VT 也是如此。因此它们的形状为 (m,m) 和 (n,n)

这似乎对我的情况没有用,我想进行降维,但 SVD 还有许多其他用途,例如查找伪逆表。

关于python - scipy.linalg.svd : shapes of VT and U: what is full_matrices and why is it needed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54987801/

相关文章:

python - 获取列表特定范围内的元素

Python字符串——交换括号内和括号外的位置

python - 如果 key 不在东西上,或者如果不在东西上 key ?

python - SciPy:稀疏数据的 n 维插值

recommendation-engine - 将内容信息与基于分解的协同过滤相集成

c++ - 从 C++ 调用 Julia SVD

python - 使用过滤器通过 django-polymorphic 限制 GenericForeignKey 模型列表

python - VS Code 中的 Jupyter 使用错误版本的 scipy

python - 马氏距离在 rpy2 和 scipy 之间不匹配

matlab - 使用 SVD 而不是协方差矩阵来计算特征脸