fftn

paddle.fft. fftn ( x, s=None, axes=None, norm='backward', name=None ) [source]

Compute the N-D discrete Fourier Transform.

This function calculates the n-D discrete Fourier transform on any number of axes in the M-D array by fast Fourier transform (FFT).

Parameters
  • x (Tensor) – The input data. It’s a Tensor type. It’s a complex.

  • s (sequence of ints, optional) – Shape (length of each transformed axis) of the output (s[0] refers to axis 0, s[1] to axis 1, etc.). This 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 used to calculate FFT. If not given, the last len(s) axes are used, or all axes if s is also not specified.

  • norm (str, optional) – Indicates which direction to scale the forward or backward transform pair and what normalization factor to use. The parameter value must be one of “forward” or “backward” or “ortho”. Default is “backward”, meaning no normalization on the forward transforms and scaling by 1/n on the ifft. “forward” instead applies the 1/n factor on the forward tranform. For norm="ortho", both directions are scaled by 1/sqrt(n).

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

complex tensor. The truncated or zero-padded input, transformed along the axes indicated by axes, or by a combination of s and x, as explained in the parameters section above.

Examples

import numpy as np
import paddle

x = np.mgrid[:4, :4, :4][1]
xp = paddle.to_tensor(x)
fftn_xp = paddle.fft.fftn(xp, axes=(1, 2)).numpy()
print(fftn_xp)
#  [[[24.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+8.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.-8.j  0.+0.j  0.+0.j  0.-0.j]]
#   [[24.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+8.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.-8.j  0.+0.j  0.+0.j  0.-0.j]]
#   [[24.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+8.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.-8.j  0.+0.j  0.+0.j  0.-0.j]]
#   [[24.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+8.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.+0.j  0.+0.j  0.+0.j  0.-0.j]
#   [-8.-8.j  0.+0.j  0.+0.j  0.-0.j]]]