小编Lex*_*exi的帖子

np.int16 和 int16 matlab 之间的区别?

我正在将 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) 有不同的答案!)你能帮我得到相同的答案吗?

python matlab numpy type-conversion complex-numbers

4
推荐指数
2
解决办法
47
查看次数

标签 统计

complex-numbers ×1

matlab ×1

numpy ×1

python ×1

type-conversion ×1