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

SciPy · Function

fft.fft

Computes a one-dimensional discrete Fourier transform using the fast Fourier transform algorithm. It transforms the selected axis, optionally changing its length and normalization.

How it works

The function transforms one selected axis of an array into its discrete Fourier representation using the FFT algorithm. The optional length can crop or zero-pad that axis, while normalization controls scaling between forward and inverse transforms.

Syntax

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

Parameters

NameTypeDescription
xarray_likeInput array; it may contain complex values.
nint, optionalOutput length along the transformed axis; defaults to that axis's input length.
axisint, optionalAxis along which to compute the transform; defaults to the last axis.
norm{“backward”, “ortho”, “forward”}, optionalNormalization mode: backward, ortho, or forward.
overwrite_xbool, optionalWhether the input may be overwritten to reduce memory use.
workersint, optionalNumber of workers to use for computation.
planobject, optionalReserved parameter for vendor-specific FFT plans; currently unused.

Returns

A complex-valued array containing the one-dimensional discrete Fourier transform, with the transformed axis having length n or its original length when n is omitted.

Key points

  • Use fft to convert a one-dimensional sequence into its discrete Fourier-domain representation.
  • The implementation uses the FFT algorithm rather than a direct DFT computation.
  • The n argument determines the output length along the transformed axis.
  • For multidimensional inputs, axis defaults to the final dimension.
  • The ortho mode applies symmetric inverse-square-root length scaling.

Common mistakes

  • Choosing an n shorter than the selected input axis discards samples.
  • Choosing an n longer than the selected input axis adds zero samples before transforming.
  • The default normalization leaves the forward transform unscaled; account for this when comparing amplitudes.
  • Orthogonal normalization changes the scaling of both forward and inverse transforms.

Example: Transform and reconstruct a sequence

import numpy as np
from scipy.fft import fft, ifft

x = np.array([1.0, 0.0, -1.0, 0.0])
spectrum = fft(x)
reconstructed = ifft(spectrum)

print(spectrum)
print(np.allclose(reconstructed, x))

Computes the spectrum of a short real sequence and verifies that the inverse transform reconstructs the input.

When to use it

Spectral analysis

Inspecting frequency content in sampled signals.

Frequency-domain processing

Converting convolution or filtering work into the frequency domain.

Axis-specific array transforms

Transforming each row or column of a multidimensional array.

Interview questions

QWhat does scipy.fft.fft compute, and where does it operate?

It computes a one-dimensional discrete Fourier transform with the efficient Fast Fourier Transform algorithm. The transform is applied along the selected axis, which defaults to the last axis.

Follow-up: How can the transform length differ from the input length? Set n explicitly: a smaller value crops the selected axis and a larger value zero-pads it.

QHow do n and axis affect the result?

n specifies the output length along the transformed axis. Omitting it uses the input length along axis; setting it changes the length by cropping or zero-padding.

Follow-up: Which axis is affected? The axis argument identifies it, and its default value is -1, the last axis.

QWhat are the normalization modes?

The default backward mode applies no scaling to the forward transform and uses 1/n scaling on ifft. forward applies 1/n to the forward transform, while ortho scales both directions by 1/sqrt(n).

Follow-up: When is ortho useful? It provides symmetric scaling between the forward and inverse operations.

  • scipy.fft.ifft
  • scipy.fft.fft2
  • scipy.fft.fftn
  • scipy.fft.rfft
  • scipy.fft.rfftfreq

Source: FFT. Checked 2026-10-15.