What is the difference between numpy.fft.fft and numpy.fft.rfft?

the reason is explained in the docs:

When the DFT is computed for purely real input, the output is Hermitian-symmetric, i.e. the negative frequency terms are just the complex conjugates of the corresponding positive-frequency terms, and the negative-frequency terms are therefore redundant. This function does not compute the negative frequency terms, and the length of the transformed axis of the output is therefore n//2 + 1.

As a consequence, the algorithm is optimized and rfft is twice as fast. Furthermore, the spectrum is easier to plot :

In [124]: s=abs(sin(arange(0,2**13,3)))

In [125]: sp=rfft(s)

In [126]: plot(abs(sp))

enter image description here


Basic difference is explained here via example. As it says:

import numpy as np

data = [0, 1, 2, 1, 0]

print("FFT output\n", np.fft.fft(data))
print("RFFT output\n", np.fft.rfft(data))

will result in:

FFT output
 [ 4.        +0.j         -2.11803399-1.53884177j  0.11803399+0.36327126j
  0.11803399-0.36327126j -2.11803399+1.53884177j]
RFFT output
 [ 4.        +0.j         -2.11803399-1.53884177j  0.11803399+0.36327126j]

Notice how the final element of the fft output is the complex conjugate of the second element, for real input. For rfft, this symmetry is exploited to compute only the non-negative frequency terms.