
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - fftn() Function
The scipy.fft.fftn() function calculates the N-dimensional Fast Fourier Transform (FFT) of an input array. This expands the FFT to higher dimensions enabling frequency analysis and manipulation of data with multiple dimensions.
This function proves valuable to process or analyze applications that need multidimensional data, like 3D images in medical imaging and CT scans multidimensional simulations, or 3D spectrograms in audio and signal processing.
Syntax
The syntax for the SciPy fftn() method is as follows −
.fftn(x, s=None, axes=None, norm=None, overwrite_x=False, workers=None, *, plan=None)
Parameters
This method accepts the following parameters −
x (array_like) − Input array containing the data to be transformed.
s (sequence of ints, optional) − Shape of the output along each transformed axis. Pads or truncates the input array accordingly.
axes (sequence of ints, optional) − Axes over which to compute the FFT. Defaults to all axes.
norm (str, optional) − The normalization mode control over scaling: "backward" (default, no scaling), "ortho" (unitary scaling for energy preservation), and "forward" (scales the output by 1/n, where n is the transform length).
overwrite_x (bool, optional) − If True, allows the input array x to be overwritten for better performance. Default is False.
workers (int, optional) − Number of parallel workers to use for computation. Default is None, meaning a single thread is used.
plan (optional) − A precomputed plan for optimized repeated FFT computations (not commonly used).
Return Value
out(complex ndarray) − The N-dimensional FFT of the input array, containing complex numbers representing frequency components.
Example 1
This example shows how the fftn() function determines the N-dimensional Fast Fourier Transform of a basic 2D array.
The result is a complex array where each element represents a frequency's magnitude and phase in the frequency domain.
import numpy as np import scipy.fft from scipy.fft import fftn # Define a 2D input array x = np.array([[1, 2], [3, 4]]) # Compute the N-Dimensional FFT result = scipy.fft.fftn(x) print("N-Dimensional FFT Result:\n", result)
When we run above program, it produces following result −
N-Dimensional FFT Result: [[10.-0.j -2.-0.j] [-4.-0.j 0.-0.j]]
Example 2
This example shows how fftn() with zero-padding increases the input array size to a required shape.
The output gains finer frequency resolution due to padding the array. The reason is that this step is essential for analyzing finer details in the frequency domain of signals or images.
import numpy as np from scipy.fft import fftn x = np.array([[1, 2], [3, 4]]) result = fftn(x, s=(4, 4)) print("FFT with Zero-Padding:\n", result)
Following is an output of the above code
FFT with Zero-Padding: [[10.-0.j 4.-6.j -2.-0.j 4.+6.j] [ 3.-7.j -3.-5.j -1.+1.j 5.-1.j] [-4.-0.j -2.+2.j 0.-0.j -2.-2.j] [ 3.+7.j 5.+1.j -1.-1.j -3.+5.j]]
Example 3
This example demonstrates how to use fftn() to examine 3D medical images such as CT and MRI scans. Scientists can use the FFT to identify frequency components from 3D data, which can aid in spotting repeating structures or filtering out noise to improve display.
The function takes a 3D dataset, such as a medical scan, and uses fftn() to convert it to the frequency domain.
The frequency components from FFT can be used to eliminate strong high-frequency noise so the images are cleaner and diagnosed more accurately. It even helps in the identification of repeated structures and highlights different frequencies.
import numpy as np from scipy.fft import fftn # Create a 3D synthetic dataset (representing a medical scan) medical_scan = np.random.rand(64, 64, 64) # Compute the N-Dimensional FFT freq_components = fftn(medical_scan) print("Frequency components of the 3D medical scan computed.")
Output of the above code is as follows −
Frequency components of the 3D medical scan computed.