Onesided 2D rfft - discards "half" of the signal only for the last dimension

Why does the onesided option work only for the last dimension, but not for the last but one in case of the 2D rfft:

``````z = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
np.fft.fft2(z)
Out[31]:
array([[136. +0.j,  -8. +8.j,  -8. +0.j,  -8. -8.j],
[-32.+32.j,   0. +0.j,   0. +0.j,   0. +0.j],
[-32. +0.j,   0. +0.j,   0. +0.j,   0. +0.j],
[-32.-32.j,   0. +0.j,   0. +0.j,   0. +0.j]])
ztorch = torch.tensor(z, dtype=torch.float)
torch.rfft(ztorch, 2)
Out[35]:
tensor([[[136.,   0.], [ -8.,   8.], [ -8.,   0.]],
[[-32.,  32.], [  0.,   0.], [  0.,   0.]],
[[-32.,   0.], [  0.,   0.], [  0.,   0.]],
[[-32., -32.], [  0.,   0.], [  0.,   0.]]])
``````

Shouldnâ€™t the last line `[[-32., -32.], [ 0., 0.], [ 0., 0.]]` be discarded as well for the onesided 2D rfft?

Yes you can indeed infer using the 2nd row. but onesided never says that it gives you the minimum set of values that has no redundant information. It just discards ~half on the last dimension, which is also the convention many fft libraries use: e.g., mklfft, fftw, cufft.