def kron(a,b): """kronecker product of a and b Kronecker product of two matrices is block matrix [[ a[ 0 ,0]*b, a[ 0 ,1]*b, ... , a[ 0 ,n-1]*b ], [ ... ... ], [ a[m-1,0]*b, a[m-1,1]*b, ... , a[m-1,n-1]*b ]] """ if not a.iscontiguous(): a = reshape(a, a.shape) if not b.iscontiguous(): b = reshape(b, b.shape) o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1)
def ifftshift(x,axes=None): """ ifftshift(x,axes=None) - > y Inverse of fftshift. """ tmp = asarray(x) ndim = len(tmp.shape) if axes is None: axes = range(ndim) y = tmp for k in axes: n = tmp.shape[k] p2 = n-(n+1)/2 mylist = concatenate((arange(p2,n),arange(p2))) y = take(y,mylist,k) return y
def fftshift(x,axes=None): """ fftshift(x, axes=None) -> y Shift zero-frequency component to center of spectrum. This function swaps half-spaces for all axes listed (defaults to all). Notes: If len(x) is even then the Nyquist component is y[0]. """ tmp = asarray(x) ndim = len(tmp.shape) if axes is None: axes = range(ndim) y = tmp for k in axes: n = tmp.shape[k] p2 = (n+1)/2 mylist = concatenate((arange(p2,n),arange(p2))) y = take(y,mylist,k) return y