scipy.fft() in Python (original) (raw)

Last Updated : 23 Jul, 2025

**scipy.fft() method in Python computes the Fast Fourier Transform (FFT) of a 1D array, converting a time-domain signal into its frequency-domain form. If no parameters are provided, it uses default settings.

**Fast Fourier Transformation Formula:

y[k] = \sum_{n=0}^{N-1} e^{-2\pi j \frac{kn}{N}} x[n]

Where:

**Example:

Python `

import numpy as np from scipy.fft import fft

x = np.array([1, 2, 3, 4]) res = fft(x) print(res)

`

**Output

[10.-0.j -2.+2.j -2.-0.j -2.-2.j]

**Explanation: This performs the FFT on a real-valued signal [1, 2, 3, 4]. The output is a complex array representing frequency components.

Syntax of scipy.fft()

scipy.fft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None)

**Parameters:

Parameter Type Description
x array_like Input array.
n int, optional Output length pads with zeros if n > len(x).
axis int, optional Axis to perform FFT on; defaults to last.
norm {None, "ortho"} Normalization mode, "ortho" uses orthonormal scaling.
overwrite_x bool, optional Allows input overwrite for memory efficiency.
workers int, optional Threads for computation (SciPy 1.5.0+).

**Returns: A NumPy array of complex numbers representing the frequency components of the input signal.

**Exceptions:

Examples

**Example 1: Use zero-padding with n parameter

Python `

import numpy as np from scipy.fft import fft

x = np.array([1, 2, 3, 4]) res = fft(x, n=8) print(res)

`

**Output

[10. -0.j -0.41421356-7.24264069j -2. +2.j
2.41421356-1.24264069j -2. -0.j 2.41421356+1.24264069j
-2. -2.j -0.41421356+7.24264069j]

**Explanation: By specifying n=8, the input is zero-padded to a length of 8 before applying FFT.

**Example 2: Apply FFT along a specific axis of a 2D array

Python `

import numpy as np from scipy.fft import fft

x = np.array([[1, 2], [3, 4]]) res = fft(x, axis=0) print(res)

`