gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:15:51 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com