This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / fft / _helper / fftshift

function

scipy.fft._helper:fftshift

source: build-install/usr/lib/python3.14/site-packages/scipy/fft/_helper.py:254

Signature

def fftshift(x, axes = None)

Summary

Shift the zero-frequency component to the center of the spectrum.

Extended Summary

This function swaps half-spaces for all axes listed (defaults to all). Note that y[0] is the Nyquist component only if len(x) is even.

Parameters

x : array_like

Input array.

axes : int or shape tuple, optional

Axes over which to shift. Default is None, which shifts all axes.

Returns

y : ndarray

The shifted array.

Examples

import numpy as np
freqs = np.fft.fftfreq(10, 0.1)
freqs
np.fft.fftshift(freqs)
✓
array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.])
Shift the zero-frequency component only along the second axis:
freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
freqs
np.fft.fftshift(freqs, axes=(1,))
✓
array([[ 2.,  0.,  1.],
       [-4.,  3.,  4.],
       [-1., -3., -2.]])

See also

ifftshift

The inverse of fftshift.

Aliases

  • scipy.fft.fftshift

Referenced by

This package