The inverse of `fftshift`. Although identical for even-length `x`, the functions differ by one sample for odd-length `x`. Parameters ---------- x : array_like Input array. axes : int or shape tuple, optional Axes over which to calculate. Defaults to None, w
(x, axes=None)
| 76 | |
| 77 | @array_function_dispatch(_fftshift_dispatcher, module='numpy.fft') |
| 78 | def ifftshift(x, axes=None): |
| 79 | """ |
| 80 | The inverse of `fftshift`. Although identical for even-length `x`, the |
| 81 | functions differ by one sample for odd-length `x`. |
| 82 | |
| 83 | Parameters |
| 84 | ---------- |
| 85 | x : array_like |
| 86 | Input array. |
| 87 | axes : int or shape tuple, optional |
| 88 | Axes over which to calculate. Defaults to None, which shifts all axes. |
| 89 | |
| 90 | Returns |
| 91 | ------- |
| 92 | y : ndarray |
| 93 | The shifted array. |
| 94 | |
| 95 | See Also |
| 96 | -------- |
| 97 | fftshift : Shift zero-frequency component to the center of the spectrum. |
| 98 | |
| 99 | Examples |
| 100 | -------- |
| 101 | >>> import numpy as np |
| 102 | >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) |
| 103 | >>> freqs |
| 104 | array([[ 0., 1., 2.], |
| 105 | [ 3., 4., -4.], |
| 106 | [-3., -2., -1.]]) |
| 107 | >>> np.fft.ifftshift(np.fft.fftshift(freqs)) |
| 108 | array([[ 0., 1., 2.], |
| 109 | [ 3., 4., -4.], |
| 110 | [-3., -2., -1.]]) |
| 111 | |
| 112 | """ |
| 113 | x = asarray(x) |
| 114 | if axes is None: |
| 115 | axes = tuple(range(x.ndim)) |
| 116 | shift = [-(dim // 2) for dim in x.shape] |
| 117 | elif isinstance(axes, integer_types): |
| 118 | shift = -(x.shape[axes] // 2) |
| 119 | else: |
| 120 | shift = [-(x.shape[ax] // 2) for ax in axes] |
| 121 | |
| 122 | return roll(x, shift, axes) |
| 123 | |
| 124 | |
| 125 | @set_module('numpy.fft') |