矩阵给出 Python 不同于 Matlab 的范数值

Matrix gives in Python other norm value than in Matlab

我的目标是在我的 Python 代码中使用下面在 Matlab 中定义的矩阵,但显然这些对象没有相同的范数?因此,我认为我犯了一个错误。

Tforward = np.array(np.mat('0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274; \
                   0.219417649252501   0.449283757993216   0.449283757993216   0.219417649252501  -0.219417649252501  -0.449283757993216  -0.449283757993216  -0.219417649252501; \
                   0.569359398342846   0.402347308162278  -0.402347308162278  -0.569359398342846  -0.083506045090284   0.083506045090284  -0.083506045090284   0.083506045090284; \
                  -0.083506045090284   0.083506045090284  -0.083506045090284   0.083506045090284   0.569359398342846   0.402347308162278  -0.402347308162278  -0.569359398342846; \
                   0.707106781186547  -0.707106781186547                   0                   0                   0                   0                   0                   0; \
                   0                   0   0.707106781186547  -0.707106781186547                   0                   0                   0                   0; \
                   0                   0                   0                   0   0.707106781186547  -0.707106781186547                   0                   0; \
                   0                   0                   0                   0                   0                   0   0.707106781186547  -0.707106781186547'))

sum(Tforward**2,2)

>>> array([3.00428749, 2.99571251, 2.99571251, 3.00428749, 3.00428749,
       2.99571251, 2.99571251, 3.00428749])
Tforward =  [ 0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274   0.353553390593274;
       0.219417649252501   0.449283757993216   0.449283757993216   0.219417649252501  -0.219417649252501  -0.449283757993216  -0.449283757993216  -0.219417649252501;
       0.569359398342846   0.402347308162278  -0.402347308162278  -0.569359398342846  -0.083506045090284   0.083506045090284  -0.083506045090284   0.083506045090284;
      -0.083506045090284   0.083506045090284  -0.083506045090284   0.083506045090284   0.569359398342846   0.402347308162278  -0.402347308162278  -0.569359398342846;
       0.707106781186547  -0.707106781186547                   0                   0                   0                   0                   0                   0;
                       0                   0   0.707106781186547  -0.707106781186547                   0                   0                   0                   0;
                       0                   0                   0                   0   0.707106781186547  -0.707106781186547                   0                   0;
                       0                   0                   0                   0                   0                   0   0.707106781186547  -0.707106781186547];   

sum(Tforward.^2,2)

>>> ans =

   1.00000
   1.00000
   1.00000
   1.00000
   1.00000
   1.00000
   1.00000
   1.00000

感谢任何帮助

MATLAB Sum 和Python Sum 的区别不是一回事。如果您有 MATRIX A,则 Matlab 中的 sum(A,2) 会为您提供第二列的总和。但是,在 Python 中,sum(A,2) 为您提供列表的总和,但也应用您输入到列表中的数字。

所以在 MATLAB 中你做了 sum(A(:,2)) 而在 Python 中你做了 sum(A+2)。我相信 Taha 在您想要 np.sum 而不是

的评论中是正确的