3
���h= � @ s� d Z ddlmZ ddlmZmZmZmZmZ ddl m
Z
mZ ddddgZeef Zdd
d�Z
e
e
dd
�ddd��Ze
e
dd
�ddd��Zed�ddd��Zed�ddd��Zd S )z*
Discrete Fourier Transforms - helper.py
� )�
integer_types)�integer�empty�arange�asarray�roll)�array_function_dispatch�
set_module�fftshift� ifftshift�fftfreq�rfftfreqNc C s | fS )N� )�x�axesr r �1/tmp/pip-build-5_djhm0z/numpy/numpy/fft/helper.py�_fftshift_dispatcher s r z numpy.fft)�modulec sh t � �� |dkr0tt� j��}dd� � jD �}n,t|t�rJ� j| d }n� fdd�|D �}t� ||�S )ad
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.
axes : int or shape tuple, optional
Axes over which to shift. Default is None, which shifts all axes.
Returns
-------
y : ndarray
The shifted array.
See Also
--------
ifftshift : The inverse of `fftshift`.
Examples
--------
>>> freqs = np.fft.fftfreq(10, 0.1)
>>> freqs
array([ 0., 1., 2., ..., -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.]])
Nc S s g | ]}|d �qS )� r )�.0�dimr r r �
<listcomp>D s zfftshift.<locals>.<listcomp>r c s g | ]}� j | d �qS )r )�shape)r �ax)r r r r H s )r �tuple�range�ndimr �
isinstancer r )r r �shiftr )r r r
s -
c sj t � �� |dkr0tt� j��}dd� � jD �}n.t|t�rL� j| d }n� fdd�|D �}t� ||�S )a/
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, which shifts all axes.
Returns
-------
y : ndarray
The shifted array.
See Also
--------
fftshift : Shift zero-frequency component to the center of the spectrum.
Examples
--------
>>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
>>> freqs
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
>>> np.fft.ifftshift(np.fft.fftshift(freqs))
array([[ 0., 1., 2.],
[ 3., 4., -4.],
[-3., -2., -1.]])
Nc S s g | ]}|d �qS )r r )r r r r r r s s zifftshift.<locals>.<listcomp>r c s g | ]}� j | d �qS )r )r )r r )r r r r w s )r r r r r r r r )r r r r )r r r M s #
� �?c C sz t | t�std��d| | }t| t�}| d d d }td|td�}||d|�< |