【发布时间】:2019-12-29 05:32:23
【问题描述】:
我正在尝试使用 numpy 包将一些 MATLAB 代码转换为 Python,但不确定 eig(A) 和 diag(A) 返回的确切内容,其中 A 是我的问题标题的矩阵。
我在matlab中有以下代码,例如:
[U,autoval] = eig(S);
[d,i] = sort(-diag(autoval));
% where S is a 2 x 2 matrix, [1.1762 1.2076; 1.2076 1.5364]
在 numpy 中,我可以通过以下方式复制第一行:
autoval, U = np.linalg.eig(S)
我必须取消订单。如果我在这里错了请纠正我,在MATLAB中,第一行eig(S)返回的是特征向量,第二行是特征值,与python相反?
但是在第二行中,在 MATLAB 中,返回的值如下:
d = [-2.5772 -0.1353];
i = [2 1];
在python中,我运行d, i = np.msort(- np.diag(autoval)):
d = array([-0.1353, -2.5772]) # why is the order here different
i = array([0.0, 0.0]) # why is this different
提前谢谢,干杯!!!
【问题讨论】:
标签: python matlab numpy matrix vector