我正在将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
在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
我的结果不同(我有许多不同的值,比如(1.815808483565253e+04 + 3.533772674703890e+04j)得到了不同的答案!)请问你能帮我得到相同的答案吗?