我正在尝试在 NumPy
中进行一些简单的计算。
但是突然给出了与MATLAB计算不同的结果。
这是 MATLAB 示例:
load temp; % here are the source matrices located
resp = ang_stv' * tmp;
respC = resp.'; % this is our variable to compare with Python
cd(fileparts(mfilename('fullpath')));
save('arythm_test.mat');
在这里我尝试用 Python 计算相同的结果:
dump_data = sp.io.loadmat("arythm_test.mat")
tmp = dump_data["tmp"]
ang_stv = dump_data["ang_stv"]
ref_resp = dump_data["respC"]
our_resp = np.dot(ang_stv.swapaxes(0, 1), tmp).swapaxes(0, 1)
np.testing.assert_allclose(our_resp, ref_resp)
你能告诉我,我做错了什么吗?又该如何应对呢?
附注这里是temp.mat和 arythm_test.mat
最佳答案
答案很简单:MATLAB 中的 .'
运算符表示简单转置,而 '
运算符表示复杂共轭转置。哎哟...
tmp = dump_data["tmp"]
ang_stv = dump_data["ang_stv"]
print "tmp.shape", tmp.shape
print "ang_stv.shape", ang_stv.shape
ref_resp = dump_data["respC"]
our_resp = np.dot(np.conj(ang_stv.swapaxes(0, 1)), tmp).swapaxes(0, 1)
关于python - NumPy:矩阵点积与 MATLAB 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33368894/