fft2#

ivy.fft2(x, *, s=None, dim=(-2, -1), norm='backward', out=None)[source]#

Compute the 2-dimensional discrete Fourier Transform.

Parameters:
  • x (Union[Array, NativeArray]) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT2.

  • s (Optional[Sequence[int]], default: None) – 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 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. if s is not given, the shape of the input along the axes specified by axes is used.

  • dim (Sequence[int], default: (-2, -1)) – Axes over which to compute the FFT2. If not given, the last two axes are used. A repeated index in axes means the transform over that axis is performed multiple times. A one-element sequence means that a one-dimensional FFT is performed.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by $frac{1}{sqrt{n}}$. “forward” indicates normalization by $frac{1}{n}$.

  • out (Optional[Array], default: None) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The result of the FFT2 operation.

Examples

>>> x = ivy.array([[0, 0, 0, 0, 0],
...                [1, 1, 1, 1, 1],
...                [2, 2, 2, 2, 2],
...                [3, 3, 3, 3, 3],
...                [4, 4, 4, 4, 4]])
>>> y = ivy.fft2(x)
>>> print(y)
ivy.array([[ 50.  +0.j        ,   0.  +0.j        ,   0.  +0.j        ,
          0.  +0.j        ,   0.  +0.j        ],
       [-12.5+17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
          0.  +0.j        ,   0.  +0.j        ],
       [-12.5 +4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
          0.  +0.j        ,   0.  +0.j        ],
       [-12.5 -4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
          0.  +0.j        ,   0.  +0.j        ],
       [-12.5-17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
          0.  +0.j        ,   0.  +0.j        ]])
Array.fft2(self, *, s=None, dim=(-2, -1), norm='backward', out=None)[source]#

Compute the 2-dimensional discrete Fourier Transform.

Parameters:
  • x – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT2.

  • s (Optional[Sequence[int]], default: None) – 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 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. If s is not given, the shape of the input along the axes specified by axes is used.

  • dim (Sequence[int], default: (-2, -1)) – Axes over which to compute the FFT2. If not given, the last two axes are used. A repeated index in axes means the transform over that axis is performed multiple times. A one-element sequence means that a one-dimensional FFT is performed.

  • norm (str, default: 'backward') – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • out (Optional[Array], default: None) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The result of the FFT2 operation.

Examples

>>> a = ivy.array([[0, 0, 0, 0, 0],
                [1, 1, 1, 1, 1],
                [2, 2, 2, 2, 2],
                [3, 3, 3, 3, 3],
                [4, 4, 4, 4, 4]])
>>> ivy.fft2(a)
array([[ 50.  +0.j        ,   0.  +0.j        ,   0.  +0.j        , # may vary
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5+17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5 +4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5 -4.0614962j ,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ],
    [-12.5-17.20477401j,   0.  +0.j        ,   0.  +0.j        ,
        0.  +0.j        ,   0.  +0.j        ]])