Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

fft.fft2

Computes a two-dimensional discrete Fourier transform with SciPy's FFT implementation. It can operate on selected axes of an M-D array and supports configurable sizes and normalization.

How it works

fft2 applies the Fast Fourier Transform across two selected axes of an array. By default, it operates on the final two axes; s can crop or zero-pad those axes, while norm selects the normalization convention.

Syntax

scipy.fft.fft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None)

Parameters

NameTypeDescription
xarray_likeInput array; complex values are allowed.
ssequence of ints, optionalOptional output lengths for the transformed axes. Smaller lengths crop the input; larger lengths pad it with zeros.
axessequence of ints, optionalAxes over which to compute the FFT. If omitted, the last two axes are used.
norm{“backward”, “ortho”, “forward”}, optionalNormalization mode: backward, ortho, or forward. Defaults to backward.
overwrite_xbool, optionalIf true, the input contents may be destroyed. Defaults to false.
workersint, optionalMaximum number of workers to use for parallel computation.
planobject, optionalReserved for passing a backend-specific plan; currently unused.

Returns

A complex ndarray containing the truncated or zero-padded input transformed along axes, or along the last two axes when axes is omitted.

Key points

  • Use fft2 to convert a two-dimensional spatial or sampled signal into its frequency-domain representation.
  • The function is not limited to rank-two inputs; axes selects which dimensions of an M-D array receive the transform.
  • Omitting axes targets the final two dimensions.
  • s specifies the output length for each transformed dimension, with s[0] corresponding to the first listed axis.
  • A requested s length smaller than the input truncates data along that axis.
  • norm controls scaling and supports backward, ortho, and forward modes.

Common mistakes

  • When a requested shape in s exceeds the input size, fft2 zero-pads the corresponding axis.
  • Setting overwrite_x=True permits the input contents to be destroyed, so avoid it when the original array must remain unchanged.

Example: Transform and invert a 2-D array

import numpy as np
from scipy.fft import fft2, ifft2

image = np.eye(4)
spectrum = fft2(image)
reconstructed = ifft2(spectrum)

print(np.allclose(reconstructed, image))

Computes a forward 2-D FFT and reconstructs the input with the inverse transform.

When to use it

Analyze 2-D spatial frequencies

Image and matrix frequency analysis

Transform data before applying frequency-domain operations

Spectral filtering

Transform selected planes in an M-D dataset

Multidimensional arrays

Interview questions

QWhat does scipy.fft.fft2 compute?

fft2 computes a 2-D discrete Fourier transform using the Fast Fourier Transform. It can also transform any chosen axes of an M-D input array.

Follow-up: How can the transformed dimensions be controlled? Use s to provide the output length for each transformed axis and axes to identify those axes.

QWhich axes does fft2 use by default?

With no axes argument, fft2 transforms the last two axes. For an M-D array, this produces a 2-D transform independently across the remaining dimensions.

Follow-up: What happens if s is shorter than the input? The data is cropped along that transformed axis.

QHow does normalization work?

The default normalization is backward. The norm argument also accepts ortho and forward, matching the normalization choices documented for fft.

Follow-up: How do you recover the original array? Apply ifft2 with compatible s, axes, and norm settings.

  • scipy.fft.fft
  • scipy.fft.ifft2
  • scipy.fft.fftn

Source: Fft2. Checked 2026-10-15.