How to get complex64 output from numpy.fft?

1.4k Views Asked by At

I have the following code:

Ga=rfft2(A)

A is type float32, but Ga comes out as complex128 effectively doubling my data. How can I get out complex64 data? Certainly this isn't the default functionality for fftw?

1

There are 1 best solutions below

1
On

Well, it seems that the type is defined quite deep in the C code. fftpack_litemodule.c uses NPY_CDOUBLE as the array type and that is basically your complex128. The only solution that I see is to transform the array to complex64 using astype(np.complex64) or to use the scipy.fftpack package which returns an array of float64 encoding the complex values as:

[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2))]              if n is even
[y(0),Re(y(1)),Im(y(1)),...,Re(y(n/2)),Im(y(n/2))]   if n is odd