Why is the last value of an RFFT always real?

I am using numpy to do FFTs of real-valued data. And I don't understand why the Nyquist frequency is always real (or has zero phase).

So, say A = rfft(data) then A[-1] is always a real value, and not complex. Is this the correct value for that frequency? Or is this a computational artifact that can be fixed?

The explanation given in the documentation is:

A[-1] contains the term representing both positive and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely real.

Is there a way to extract only the positive frequency and get rid of the degeneracy in the imaginary component caused by the Hermitian nature of the real FFT?

The real component of an FFT or DFT represents cosine or even sinusoids (symmetric around the middle), and the imaginary component represents sine, or odd sinusoids (anti-symmetric around the center). An anti-symmetric waveform has to be zero at the center of an even length window. If a sinusoid of frequency Fs/2 is zero at any sample, it is zero at all samples taken at a sample rate of Fs. The imaginary component of the basis vector at N/2 for a DFT transform is also all zeros for the same reason. Thus the imaginary bin at Fs/2 is the sum of zero times zero, and has to be zero. Leaving the result in bin N/2 strictly real for even length DFTs. Perhaps this is the bin your RFFT implementation reports for A(-1).

The is also the reason why Nyquist sampling has to be at a rate ABOVE the_highest_frequency / 2, not equal to. Sampling will leave out part of any anti-symmetric waveform or waveform component (in any even length set of samples) if that component is of exactly frequency F when sampled at F/2.

There are different rules for odd length FFTs.

Think about it: the FFT at the end will be taken using the "complex" exponential with values [1 -1 1 -1 1 -1 ...] which will always be real valued. If the signal is also real valued, then that coefficient cannot be complex.

The quadrature (or imaginary) part gives information on the phase of the component, but with a real input, both the first component (zero frequency or DC) and the last component have no such phase information available. As described in other answers, the coefficients for this component are +-1 (just as the coefficients of the zero frequency component is all +1) so it can only measure an amplitude. The phase of this last component will be reflected in the amplitude; a phase of zero will be full amplitude (it will also be +-1 at each sample instant), a phase of 90 degrees will zero at all sample instants.

Note that the component could have a negative value, so "no phase information" may not be the perfect description.