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

SciPy · Function

fft

Computes a one-dimensional discrete Fourier Transform using the Fast Fourier Transform algorithm. You can control output length, transformed axis, normalization, and optional parallel execution.

How it works

fft converts an input sequence into its one-dimensional discrete Fourier Transform using the Fast Fourier Transform algorithm. The transformed length defaults to the selected axis length, while n can crop or zero-pad that axis; norm selects how scaling is distributed 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, which may contain complex values.
nint, optionalLength of the transformed axis. If shorter than the input it crops; if longer it zero-pads; if omitted it uses that axis's length.
axisint, optionalAxis over which to compute the FFT; defaults to the last axis.
norm{“backward”, “ortho”, “forward”}, optionalNormalization mode: “backward”, “ortho”, or “forward”.
overwrite_xbool, optionalWhether the input may be overwritten for performance.
workersint, optionalNumber of workers to use for parallel computation.
planobject, optionalReserved for passing a vendor-specific FFT plan; currently not used.

Returns

The transformed array containing the one-dimensional discrete Fourier Transform of x.

Key points

  • Use fft to convert a one-dimensional sampled signal into its discrete Fourier Transform.
  • The implementation uses the Fast Fourier Transform algorithm rather than a direct DFT calculation.
  • The n parameter sets the output length along the selected transform axis.
  • When axis is omitted, fft operates on the final array dimension.
  • The input may contain complex-valued samples.

Common mistakes

  • Choosing an n shorter than the input discards samples along the transformed axis.
  • Choosing an n longer than the input adds zero samples before transforming.
  • The default normalization leaves the forward result unscaled and applies the reciprocal-length factor to ifft.

Example: Compute a one-dimensional FFT

import numpy as np
from scipy.fft import fft

samples = np.array([1.0, 0.0, -1.0, 0.0])
spectrum = fft(samples)
print(spectrum)

Transforms a short real-valued signal into its complex frequency-domain representation.

When to use it

Frequency analysis

Analyze the frequency components of a sampled time-domain signal.

Axis-specific transforms

Transform multidimensional data one row or column at a time.

Fixed-length spectral processing

Control spectral resolution or input length by cropping or zero-padding.

Interview questions

QWhat does scipy.fft.fft compute?

fft computes a one-dimensional discrete Fourier Transform with the efficient Fast Fourier Transform algorithm. It returns the frequency-domain representation of the supplied array.

Follow-up: How does n affect the calculation? It determines the transformed-axis length: a shorter value crops the input, and a longer value zero-pads it.

QHow does fft choose the transformed axis?

The axis argument selects the dimension to transform and defaults to the last axis. This allows FFTs to be applied independently across other dimensions.

Follow-up: What happens when axis is omitted? SciPy uses the final axis of the input array.

QHow does normalization work?

norm controls scaling, with backward, ortho, and forward modes available. backward is the default; it leaves the forward transform unscaled and scales ifft by 1/n.

Follow-up: Which mode scales the forward transform? forward applies the 1/n factor on the forward transform.

  • ifft
  • fftn
  • rfft
  • next_fast_len

Source: FFT. Checked 2026-10-15.