from numpy.core import asarray, concatenate,swapaxes import numpy.core.numerictypes as nt def fftshift(x,axes=None): tmp = asarray(x) if axes is None: axes = range(tmp.ndim) elif isinstance(axes, (int, nt.integer)): axes = (axes,) y = tmp for k in axes: n = tmp.shape[k] p2 = (n+1)//2 y = swapaxes(y,0,k) y = concatenate((y[p2:,...], y[:p2,...])) y = swapaxes(y,0,k) return y