# Reason behind different outputs for Fast Fourier Transform in Numpy and Matlab

Here is the output of Numpy

np.fft.ifft([0, 4, 0, 0])
array([ 1.+0.j,  0.+1.j, -1.+0.j,  0.-1.j]) # may vary


Here is the output of Matlab

res = fft([0, 4, 0, 0])

res =

4.0000 + 0.0000i   0.0000 - 4.0000i  -4.0000 + 0.0000i   0.0000 + 4.0000i

ifft(res)

ans =

0     4     0     0


What is the reason behind different outputs for composition of FFT & iFFT in Numpy and Matlab considering that both of them are used for scientific computation?
How to remedy the problem above in Numpy so I can get the expected result?(Same result as Matlab)

• How about if you run np.fft.fft([0,4,0,0]) first, then run np.fft.ifft on the resulting array? Does that match with MATLAB? – Abdullah Ali Sivas Mar 5 at 13:55
• I think you were misinterpreting what np.fft does. np.fft access the fft class -- it does not perform a discreet fourier transform. I think you meant to try np.fft.ifft(np.fft.fft([0, 4, 0, 0])) – Charlie S Mar 5 at 14:20
• Not sure what the problem is. All the results are the same as matlab. ideone.com/4Emi16 – Charlie S Mar 5 at 18:46
• See my first comment, I believe you are misunderstanding what np.fft.fft is doing. The first .fft is accessing a set of instructions related to the FFT, including the forward FFT, the inverse FFT, and probably a bunch of other things if you read the documentation. np.fft.fft is only calling the FFT once. – Charlie S Mar 5 at 19:03
• @FreeMind No problem. It is confusing that the class has the same name as one of the routines. – Charlie S Mar 5 at 19:19

The FFT is in principle a length-preserving operation. For that there has to be a factor 1/N to be distributed between the forward and inverse transform. It is a design decision where that is done or if it is done at all.
It appears that in both cited cases the division by N is performed for the inverse transform. You can interpret the ifft result as polynomial coefficients,
p(z) = 1 + j*z - z^2 - j*z^3

where you get the original vector as the polynomial values at [1,-j,-1,j].