为什么C++;犰狳不同于Python和R

为什么C++;犰狳不同于Python和R,python,c++,r,armadillo,eigenvector,Python,C++,R,Armadillo,Eigenvector,我想知道为什么Armadillo的特征向量中元素的符号与Python(即numpy)和R等其他语言相反 例如: C++ 输出 Eigen Vectors -5.7735e-01 -7.071068e-01 0.4082483 -5.7735e-01 9.714451e-e17 -0.8164966 -5.7735e-01 7.017068e-01 0.4082483 -4.082483e-01 -7.071068e-01 5.773503e-01 8.164966e-01

我想知道为什么Armadillo的特征向量中元素的符号与Python(即numpy)和R等其他语言相反

例如:

C++

输出

Eigen Vectors
-5.7735e-01  -7.071068e-01  0.4082483
-5.7735e-01  9.714451e-e17  -0.8164966
-5.7735e-01  7.017068e-01   0.4082483
-4.082483e-01  -7.071068e-01   5.773503e-01
 8.164966e-01   9.420555e-16   5.773503e-01
-4.082483e-01   7.071068e-01   5.773503e-01
蟒蛇

import numpy as np
w,v = np.linalg.eig(np.array([[1,-1,0],[-1,2,-1],[0,-1,1]]))
v 
输出

array([[ -4.08248290e-01,  -7.07106781e-01,   5.77350269e-01],
       [  8.16496581e-01,   2.61214948e-16,   5.77350269e-01],
       [ -4.08248290e-01,   7.07106781e-01,   5.77350269e-01]])
R

输出

Eigen Vectors
-5.7735e-01  -7.071068e-01  0.4082483
-5.7735e-01  9.714451e-e17  -0.8164966
-5.7735e-01  7.017068e-01   0.4082483
-4.082483e-01  -7.071068e-01   5.773503e-01
 8.164966e-01   9.420555e-16   5.773503e-01
-4.082483e-01   7.071068e-01   5.773503e-01

可以看到Python和R提供了相同的特征向量(不包括舍入错误)。犰狳结果确实提供了相同的数字(顺序很简单),但第一列和第三列上的符号与Python和R中相应的列相反。我是否忽略了此处的某些内容?

在R中由
help(eigen)
回答:

Value:

     The spectral decomposition of ‘x’ is returned as components of a
     list with components

  values: a vector containing the p eigenvalues of ‘x’, sorted in
          _decreasing_ order, according to ‘Mod(values)’ in the
          asymmetric case when they might be complex (even for real
          matrices).  For real asymmetric matrices the vector will be
          complex only if complex conjugate pairs of eigenvalues are
          detected.

 vectors: either a p * p matrix whose columns contain the eigenvectors
          of ‘x’, or ‘NULL’ if ‘only.values’ is ‘TRUE’.  The vectors
          are normalized to unit length.

          Recall that the eigenvectors are only defined up to a
          constant: even when the length is specified they are still
          only defined up to a scalar of modulus one (the sign for real
          matrices).

所以符号是一个“自由”参数,结果是真正等价的。如果是我,我会跟随R和Python,但康拉德通常知道他在做什么。

这是由R中的
help(eigen)
回答的:

Value:

     The spectral decomposition of ‘x’ is returned as components of a
     list with components

  values: a vector containing the p eigenvalues of ‘x’, sorted in
          _decreasing_ order, according to ‘Mod(values)’ in the
          asymmetric case when they might be complex (even for real
          matrices).  For real asymmetric matrices the vector will be
          complex only if complex conjugate pairs of eigenvalues are
          detected.

 vectors: either a p * p matrix whose columns contain the eigenvectors
          of ‘x’, or ‘NULL’ if ‘only.values’ is ‘TRUE’.  The vectors
          are normalized to unit length.

          Recall that the eigenvectors are only defined up to a
          constant: even when the length is specified they are still
          only defined up to a scalar of modulus one (the sign for real
          matrices).

所以符号是一个“自由”参数,结果是真正等价的。如果是我,我会学习R和Python,但康拉德通常知道他在做什么。

你没有使用好的功能(你的函数是用于symetric Martix的)


您没有使用良好的功能(您的功能用于symetric Martix)


如果
v
是特征向量,那么
av
(a是实数)也是特征向量。通常的惯例是规范化它们,但它们仍然可以指向两个可能的方向中的任何一个。如果将一个特征向量与一个标量相乘,它将保持相同特征值的特征向量。因此,只要特征向量不为零,特征向量是否相差一个常数并不重要。如果
v
是特征向量,那么
av
(a是实数)也是特征向量。通常的惯例是规范化它们,但它们仍然可以指向两个可能的方向中的任何一个。如果将一个特征向量与一个标量相乘,它将保持相同特征值的特征向量。因此,如果特征向量相差一个常数因子,只要它们不为零,这并不重要。谢谢你,德克,我只是想弄清楚这个“自由符号”参数是如何分配的。我正在R中创建一些函数来使用armadillo,我想确保输出与R相等。我是否要忽略符号并将它们称为相等?我看没有理由不这样做。谢谢你,德克,我只是想弄清楚这个“自由符号”参数是如何分配的。我正在R中创建一些函数来使用armadillo,我想确保输出与R相等。我是否要忽略符号并将它们称为相等?我看没有理由不这样做。
A :
   1.0000  -1.0000        0
  -1.0000   2.0000  -1.0000
        0  -1.0000   1.0000
eigval
    (+3.000e+00,+0.000e+00)
    (+1.000e+00,+0.000e+00)
    (-3.368e-17,+0.000e+00)
eigvec
   (-4.082e-01,+0.000e+00)    (-7.071e-01,+0.000e+00)    (+5.774e-01,+0.000e+00)
   (+8.165e-01,+0.000e+00)    (+2.612e-16,+0.000e+00)    (+5.774e-01,+0.000e+00)
   (-4.082e-01,+0.000e+00)    (+7.071e-01,+0.000e+00)    (+5.774e-01,+0.000e+00)