rfftn#

ivy.rfftn(x, s=None, axes=None, *, norm=None, out=None)[source]#

Compute the N-dimensional discrete Fourier Transform for real input.

Parameters:
  • x (array_like) – Input array, taken to be real.

  • s (sequence of ints, optional) – Shape (length along each transformed axis) to use from the input. (s[0] refers to axis 0, s[1] to axis 1, etc.). The final element of s corresponds to n for rfft(x, n), while for the remaining axes, it corresponds to n for fft(x, n). Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. If s is not given, the shape of the input along the axes specified by axes is used.

  • axes (sequence of ints, optional) – Axes over which to compute the FFT. If not given, the last len(s) axes are used, or all axes if s is also not specified.

  • norm ({"backward", "ortho", "forward"}, optional) – Normalization mode. Default is “backward”. Indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor.

  • out (array_like, optional) – Optional output array to store the result of the computation. The shape and dtype of this array must match the expected output.

Return type:

Array

Returns:

out (complex ndarray) – The truncated or zero-padded input, transformed along the axes indicated by axes or by a combination of s and a, as explained in the parameters section above. The length of the last axis transformed will be s[-1] // 2 + 1, while the remaining transformed axes will have lengths according to s, or unchanged from the input.

Raises:
  • ValueError – If s and axes have different lengths.

  • IndexError – If an element of axes is larger than the number of axes of a.

Examples

>>> x = ivy.array([1, 2, 3, 4], dtype=ivy.float32)
>>> result = ivy.rfftn(x, s=(4,), axes=(0,))
>>> print(result)
ivy.array([10.+0.j, -2.+2.j, -2.+0.j])
>>> x = ivy.array([[1, 2, 3], [4, 5, 6]], dtype=ivy.float32)
>>> result = ivy.rfftn(x, s=(3, 4), axes=(0, 1))
>>> print(result)
ivy.array([[21.         +0.j        , -4.         -7.j        ,
         7.         +0.j        ],
       [-1.5       -12.99038106j, -5.33012702 +2.23205081j,
        -0.5        -4.33012702j],
       [-1.5       +12.99038106j,  3.33012702 -1.23205081j,
        -0.5        +4.33012702j]])
Array.rfftn(self, s=None, axes=None, *, norm='backward', out=None)[source]#

Compute the n-dimensional discrete Fourier Transform.

Parameters:
  • self (Array) – Input array.

  • s (Optional[Sequence[int]], default: None) – Shape (length of each transformed axis) of the output.

  • axes (Optional[Sequence[int]], default: None) – Axes over which to compute the RFFT. If not given, the last len(s) axes are used.

  • norm (str, default: 'backward') – Normalization mode: “backward”, “ortho”, or “forward”.

  • out (Optional[Array], default: None) – Optional output array for writing the result.

Return type:

Array

Returns:

ret – The result of the RFFT operation.

Container.rfftn(self, s=None, axes=None, *, norm='backward', out=None)[source]#

Compute the n-dimensional discrete Fourier Transform for real input.

Parameters:
  • axes (int or tuple of ints, optional) – Axes over which to compute the FFT. If not given, the last n axes are used.

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output. Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros.

  • norm ({'backward', 'ortho', 'forward'}, optional) – Normalization mode. Default is ‘backward’.

  • out (array-like, optional) – Output array. Must have the same shape and type as the expected output.

Return type:

Container

Returns:

transformed (Container) – The n-dimensional discrete Fourier Transform of the input.