This must be a stupid question but I could not figure what is wrong by myself. I wanted to test pyfftw so I ran the following code:
import numpy as np
import pyfftw
a = np.random.randn(2,64,64)
b = np.zeros(2,64,33)*np.complex(0.)
pyfftw.FFTW(a,b,axes = (-2,-1), direction = 'FFTW_FORWARD')
I expect that the array b
to be changed to the Fourier modes of array a
. But it turns out that b
is still all zeros. So what is wrong here? Can anyone give a hint? Thank you very much.
Here is the follow up. Thanks AKX and Hamaza for pointing out that I should run the execute() method to get the FFT done. But Now there is another issue. I tried calling pyfftw in a self-defined function. The output shows that the input array is changed to all zeros.
def f2fh(f):
ftmp = np.copy(f)
nz,nx,ny = f.shape
nky = ny
nkx = (nx/2)+1
fh = np.zeros((nz,nky,nkx))*np.complex(0.)
print 'ksksks',ftmp.shape,fh.shape,ftmp
pyfftw.FFTW(ftmp, fh, axes = (-2,-1), direction = 'FFTW_FORWARD').execute()
print 'a',ftmp
return fh
Can anyone give a hint what is wrong this time? Thanks a lot...
You're not calling
execute()
. Via the docs:You might also want to use the "easier" interfaces described over here: