dpnp.fft.fftshift

dpnp.fft.fftshift(x, axes=None)[source]

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 out[0] is the Nyquist component only if len(x) is even.

For full documentation refer to numpy.fft.fftshift.

Parameters:
  • x ({dpnp.ndarray, usm_ndarray}) -- Input array.

  • axes ({None, int, list or tuple of ints}, optional) -- Axes over which to shift. Default is None, which shifts all axes.

Returns:

out -- The shifted array.

Return type:

dpnp.ndarray

See also

dpnp.fft.ifftshift

The inverse of dpnp.fft.fftshift.

Examples

>>> import dpnp as np
>>> freqs = np.fft.fftfreq(10, 0.1)
>>> freqs
array([ 0.,  1.,  2.,  3.,  4., -5., -4., -3., -2., -1.])
>>> 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
array([[ 0.,  1.,  2.],
       [ 3.,  4., -4.],
       [-3., -2., -1.]])
>>> np.fft.fftshift(freqs, axes=(1,))
array([[ 2.,  0.,  1.],
       [-4.,  3.,  4.],
       [-1., -3., -2.]])