SciPy IFFT: Inverse Discrete Fourier Transform in Python

SciPy IFFT is used to convert frequency-domain values back into a time-domain or signal-domain sequence. In Python, the modern function for this operation is scipy.fft.ifft(). Older code often uses scipy.fftpack.ifft(), which is the function shown in the original example below.

The inverse fast Fourier transform is commonly used after applying fft(). If you calculate fft(x) and then apply ifft() on the result, you get back the original input values, except for small floating-point differences and complex-number formatting.

SciPy ifft() syntax using scipy.fftpack

</>
Copy
  y = scipy.fftpack.ifft(x, n=None, axis=-1, overwrite_x=False)

The syntax above uses scipy.fftpack.ifft(). For new programs, you can usually import ifft from scipy.fft instead. The basic idea is the same: pass the Fourier-transformed array and get the inverse transform as a complex array.

</>
Copy
from scipy.fft import ifft

Parameters of scipy.fftpack.ifft()

Parameter Required/
Optional
[datatype] Description
xRequired[array] Array on which IFFT has to be calculated.
nOptional[int] Length of the Fourier transform. If n < x.shape[axis], x is truncated. If n > x.shape[axis], x is zero-padded. The default results in n = x.shape[axis].
axisOptional[int] Axis along which the fft’s are computed; the default is over the last axis (i.e., axis=-1).
overwrite_xOptional[boolean] If True, the contents of x can be destroyed; the default is False.
y[Returned value][complex ndarray] Inverse Discrete Fourier Transform of x.

Values provided for the optional arguments are default values. The returned array is complex even when the original signal contains only real numbers. When the imaginary part is only a tiny numerical error, you may display or compare the real part separately.

Basic SciPy IFFT example with fft() and ifft()

In this example, we first calculate the FFT of a NumPy array and then apply IFFT to reconstruct the original array.

scipy-example.py

</>
Copy
# import numpy
import numpy as np

# import fft
from scipy.fftpack import fft, ifft

# numpy array
x = np.array([1.0, 2.0, 1.0, 2.0, -1.0])
print("x            : ",x)

# apply fft function on array
y = fft(x)
print("fft(x)       : ",y)

# ifft (y)
z = ifft(y)
print("ifft(fft(x)) : ",z)

Output

x            :  [ 1.  2.  1.  2. -1.]
fft(x)       :  [ 5.00000000+0.j         -1.11803399-2.2653843j   1.11803399-2.71441227j
  1.11803399+2.71441227j -1.11803399+2.2653843j ]
ifft(fft(x)) :  [ 1.+0.j  2.+0.j  1.+0.j  2.+0.j -1.+0.j]

The final output is shown with +0.j because IFFT returns complex values. In this case, the imaginary parts are zero, so the real values match the original input array.

SciPy ifft() example using scipy.fft for new code

The scipy.fft module is the preferred interface for FFT operations in newer SciPy code. The following example performs the same round trip using scipy.fft.fft() and scipy.fft.ifft().

</>
Copy
import numpy as np
from scipy.fft import fft, ifft

x = np.array([4.0, 1.0, 3.0, 2.0])

frequency_values = fft(x)
reconstructed = ifft(frequency_values)

print(reconstructed)

Output

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

When you need only the real part for display, use reconstructed.real. Do this only when you know the original signal is real-valued and the imaginary part is just numerical round-off.

Using n in SciPy IFFT to control output length

The n argument controls the length used for the inverse transform. If n is smaller than the input length, the input is truncated. If n is larger, the input is padded with zeros before the transform is calculated.

</>
Copy
import numpy as np
from scipy.fft import ifft

values = np.array([10.0, 2.0, 1.0, 2.0])

print(ifft(values, n=4))
print(ifft(values, n=6))

Output

[3.75+0.j   2.25+0.j   1.75+0.j   2.25+0.j  ]
[2.5       +0.j         1.16666667+0.28867513j 1.66666667-0.28867513j
 1.5       +0.j         1.66666667+0.28867513j 1.16666667-0.28867513j]

Use n carefully because changing the transform length changes the reconstructed sequence. For a simple FFT-to-IFFT round trip, keep the same length unless you intentionally want padding or truncation.

Using axis in SciPy IFFT for two-dimensional arrays

By default, ifft() works along the last axis of the input array. For a two-dimensional array, this means the inverse transform is applied row by row. You can use the axis argument to apply it along a different axis.

</>
Copy
import numpy as np
from scipy.fft import fft, ifft

x = np.array([
    [1.0, 2.0, 3.0],
    [4.0, 5.0, 6.0]
])

freq = fft(x, axis=1)
result = ifft(freq, axis=1)

print(result)

Output

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

Use the same axis for fft() and ifft() when you want to reconstruct the original data along that dimension.

Why SciPy IFFT returns complex numbers

Fourier transforms work with complex frequency components. Because of this, ifft() returns a complex array. Even when the original input is real, the reconstructed result may be displayed as values such as 1.+0.j.

Small imaginary values such as 1e-16j are usually caused by floating-point arithmetic. You can check the reconstructed values with numpy.allclose() instead of comparing arrays with exact equality.

</>
Copy
import numpy as np
from scipy.fft import fft, ifft

x = np.array([1.0, 2.0, 1.0, 2.0, -1.0])
z = ifft(fft(x))

print(np.allclose(x, z.real))

Output

True

Common mistakes when using SciPy IFFT

  • Expecting only real output: ifft() returns complex values. Use .real only when it is mathematically valid for your data.
  • Changing n accidentally: A different n value can truncate or pad the input and change the result.
  • Using a different axis: If fft() was calculated along one axis and ifft() is applied along another, the result will not reconstruct the original data as expected.
  • Comparing floats with exact equality: Use numpy.allclose() for numerical comparisons.
  • Mixing old and new imports unnecessarily: Prefer scipy.fft for new code, and keep scipy.fftpack only when maintaining older examples or projects.

FAQs on SciPy IFFT in Python

What does SciPy IFFT do?

SciPy IFFT calculates the inverse discrete Fourier transform. It converts frequency-domain data back into a signal-domain sequence.

Should I use scipy.fft.ifft or scipy.fftpack.ifft?

For new Python code, use scipy.fft.ifft. The older scipy.fftpack.ifft function is still seen in many existing examples and legacy projects.

Why does ifft(fft(x)) show values like 1.+0.j?

The result is displayed as a complex number. The +0.j part means the imaginary component is zero. For real input arrays, the real part usually matches the original values within floating-point precision.

How do I get only real values from SciPy IFFT output?

You can use result.real to read the real component. Use it only when the expected output is real and the imaginary component is zero or only a tiny numerical error.

How do I verify that SciPy IFFT reconstructed the original array?

Use numpy.allclose(original, reconstructed.real) for real-valued data. This is better than exact equality because FFT and IFFT calculations may introduce small floating-point differences.

Editorial QA checklist for this SciPy IFFT tutorial

  • Confirm that the tutorial distinguishes scipy.fft.ifft from the older scipy.fftpack.ifft.
  • Check that every new Python code block uses the language-python class and every output block uses the output class.
  • Verify that the examples explain complex output instead of hiding the +0.j notation.
  • Confirm that the n and axis examples describe how output length and array dimension affect the result.
  • Make sure the FAQ answers are specific to SciPy IFFT and do not repeat generic FFT definitions unnecessarily.