MCPcopy Index your code
hub / github.com/numpy/numpy / fftshift

Function fftshift

numpy/fft/_helper.py:20–74  ·  view source on GitHub ↗

Shift the zero-frequency component to the center of the spectrum. 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. ax

(x, axes=None)

Source from the content-addressed store, hash-verified

18
19@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')
20def fftshift(x, axes=None):
21 """
22 Shift the zero-frequency component to the center of the spectrum.
23
24 This function swaps half-spaces for all axes listed (defaults to all).
25 Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
26
27 Parameters
28 ----------
29 x : array_like
30 Input array.
31 axes : int or shape tuple, optional
32 Axes over which to shift. Default is None, which shifts all axes.
33
34 Returns
35 -------
36 y : ndarray
37 The shifted array.
38
39 See Also
40 --------
41 ifftshift : The inverse of `fftshift`.
42
43 Examples
44 --------
45 >>> import numpy as np
46 >>> freqs = np.fft.fftfreq(10, 0.1)
47 >>> freqs
48 array([ 0., 1., 2., ..., -3., -2., -1.])
49 >>> np.fft.fftshift(freqs)
50 array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.])
51
52 Shift the zero-frequency component only along the second axis:
53
54 >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
55 >>> freqs
56 array([[ 0., 1., 2.],
57 [ 3., 4., -4.],
58 [-3., -2., -1.]])
59 >>> np.fft.fftshift(freqs, axes=(1,))
60 array([[ 2., 0., 1.],
61 [-4., 3., 4.],
62 [-1., -3., -2.]])
63
64 """
65 x = asarray(x)
66 if axes is None:
67 axes = tuple(range(x.ndim))
68 shift = [dim // 2 for dim in x.shape]
69 elif isinstance(axes, integer_types):
70 shift = x.shape[axes] // 2
71 else:
72 shift = [x.shape[ax] // 2 for ax in axes]
73
74 return roll(x, shift, axes)
75
76
77@array_function_dispatch(_fftshift_dispatcher, module='numpy.fft')

Callers

nothing calls this directly

Calls 2

asarrayFunction · 0.90
rollFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…