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