我正在将 matlab 代码转换为 Python。在matlab中有一行将复数转换为int16:
real = int16(real(-3.406578165491512e+04 + 9.054663292273188e+03i));
imag= int16(imag(-3.406578165491512e+04 + 9.054663292273188e+03i));
real= -32768
imag=9055
Run Code Online (Sandbox Code Playgroud)
在python中我试过这个:
real = np.int16(round(np.real(-3.406578165491512e+04 + 9.054663292273188e+03j)))
imag = np.int16(round(np.imag(-3.406578165491512e+04 + 9.054663292273188e+03j)))
real= 31470
imag=9055
Run Code Online (Sandbox Code Playgroud)
结果是不同的(我有许多其他值,例如 (1.815808483565253e+04 + 3.533772674703890e+04j) 有不同的答案!)你能帮我得到相同的答案吗?