Unexpected behavior of numpy.fft.fft with high precision numbers

后端 未结 2 1987
无人共我
无人共我 2020-12-12 03:59

I have the following code...Note the two lines under # generate sine curve. One uses a higher precision value for 2pi than the other, they should still give near identical

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 04:36

    This is totally expected behavior. Computers use floating-point computations, which are inherently imprecise.

    Note the y-axis for your real result. If no numerical inaccuracy existed, the real component would be identically 0. With your "higher precision" result, the real part is almost identical to 0 (1e-14 is very close to the precision of double-precision floats). With a lower precision, the real part becomes much larger (though still much, much smaller than the imaginary part). Because of the larger numbers, there is more structure as well (i.e. the error is not given by rounding errors, but by an actual feature of your input data, a period that is slightly shorter than ideal).

提交回复
热议问题