torch.fft.rfftn(input, s=None, dim=None, norm=None, *, out=None) → Tensor

Computes the N-dimensional discrete Fourier transform of real input.

The FFT of a real signal is Hermitian-symmetric, X[i_1, ..., i_n] = conj(X[-i_1, ..., -i_n]) so the full fftn() output contains redundant information. rfftn() instead omits the negative frequencies in the last dimension.

  • input (Tensor) – the input tensor

  • s (Tuple[int], optional) – Signal size in the transformed dimensions. If given, each dimension dim[i] will either be zero-padded or trimmed to the length s[i] before computing the real FFT. If a length -1 is specified, no padding is done in that dimension. Default: s = [input.size(d) for d in dim]

  • dim (Tuple[int], optional) – Dimensions to be transformed. Default: all dimensions, or the last len(s) dimensions if s is given.

  • norm (str, optional) –

    Normalization mode. For the forward transform (rfftn()), these correspond to:

    • "forward" - normalize by 1/n

    • "backward" - no normalization

    • "ortho" - normalize by 1/sqrt(n) (making the real FFT orthonormal)

    Where n = prod(s) is the logical FFT size. Calling the backward transform (irfftn()) with the same normalization mode will apply an overall normalization of 1/n between the two transforms. This is required to make irfftn() the exact inverse.

    Default is "backward" (no normalization).

Keyword Arguments

out (Tensor, optional) – the output tensor.


>>> t = torch.rand(10, 10)
>>> rfftn = torch.fft.rfftn(t)
>>> rfftn.size()
torch.Size([10, 6])

Compared against the full output from fftn(), we have all elements up to the Nyquist frequency.

>>> fftn = torch.fft.fftn(t)
>>> torch.allclose(fftn[..., :6], rfftn)

The discrete Fourier transform is separable, so rfftn() here is equivalent to a combination of fft() and rfft():

>>> two_ffts = torch.fft.fft(torch.fft.rfft(t, dim=1), dim=0)
>>> torch.allclose(rfftn, two_ffts)


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources