为什么 Numpy 和 Scipy QR 分解给我不同的值?

Why Numpy and Scipy QR decomposition give me different values?

我有以下向量。

x = np.array([[ 0.87695113],
              [ 0.3284933 ],
              [-0.35078323]])

当我调用 numpy 版本的 qr 时

from numpy.linalg import qr as qr_numpy
qr_numpy(x)

我得到

(array([[-0.87695113],
        [-0.3284933 ],
        [ 0.35078323]]), array([[-1.]]))

而当我 运行 scipy 版本时,我得到了完全不同的东西。

from scipy.linalg import qr as qr_scipy
qr_scipy(x)

有输出

(array([[-0.87695113, -0.3284933 ,  0.35078323],
        [-0.3284933 ,  0.94250897,  0.06139208],
        [ 0.35078323,  0.06139208,  0.93444215]]), array([[-1.],
        [ 0.],
        [ 0.]]))

这是怎么回事??

numpy.linalg.qr() is 'reduced' whereas for scipy.linalg.qr() 的默认 mode'full'

因此,要获得相同的结果,请对 scipy-qr 使用 'economic' 或对 numpy-qr 使用 'complete'

from numpy.linalg import qr as qr_numpy
qr_numpy(x)
(array([[-0.87695113],
        [-0.3284933 ],
        [ 0.35078323]]),
 array([[-1.]]))

与 scipy-qr:

的输出匹配
from scipy.linalg import qr as qr_scipy
qr_scipy(x, mode='economic')
(array([[-0.87695113],
        [-0.3284933 ],
        [ 0.35078323]]),
 array([[-1.]]))

并获得包含两者的“完整”版本:

from numpy.linalg import qr as qr_numpy
qr_numpy(x, mode='complete')
(array([[-0.87695113, -0.3284933 ,  0.35078323],
        [-0.3284933 ,  0.94250897,  0.06139208],
        [ 0.35078323,  0.06139208,  0.93444215]]),
 array([[-1.],
        [ 0.],
        [ 0.]]))
from scipy.linalg import qr as qr_scipy
qr_scipy(x)
(array([[-0.87695113, -0.3284933 ,  0.35078323],
        [-0.3284933 ,  0.94250897,  0.06139208],
        [ 0.35078323,  0.06139208,  0.93444215]]),
 array([[-1.],
        [ 0.],
        [ 0.]]))