# fft - FFT - 在python中，IFFT返回什么？

``````
a = np.arange(6)

m = ifft(fft(a))

m # Google says m should = a, but m is complex

``````

``````
array([0.+0.00000000e+00j, 1.+3.70074342e-16j, 2.+0.00000000e+00j,

3.-5.68396583e-17j, 4.+0.00000000e+00j, 5.-3.13234683e-16j])

``````

Numpy hasfunction `real_if_close`这样做

``````
>>> np.real_if_close(np.fft.ifft(np.fft.fft(a)))

array([0., 1., 2., 3., 4., 5.])

``````

``````
import numpy as np

arr = np.array(

[

0.0 + 0.00000000e00j,

1.0 + 3.70074342e-16j,

2.0 + 0.00000000e00j,

3.0 - 5.68396583e-17j,

4.0 + 0.00000000e00j,

5.0 - 3.13234683e-16j,

]

)

if all(np.isclose(arr.imag, 0)):

arr = arr.real

# [ 0. 1. 2. 3. 4. 5.]

``````

``````
import numpy as np

from numpy import fft

a = np.arange(6)

print(a)

f = np.fft.fft(a)

print(f)

m = np.fft.ifft(f)

print(m)

``````
``````
[0 1 2 3 4 5]

[15.+0.j -3.+5.19615242j -3.+1.73205081j -3.+0.j

-3.-1.73205081j -3.-5.19615242j]

[0.+0.j 1.+0.j 2.+0.j 3.+0.j 4.+0.j 5.+0.j]

``````

``````
print(m.real) # [0. 1. 2. 3. 4. 5.]

``````