
- 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 - circulant() Function
The scipy.linalg.circulant() method produces a square matrix, in which each row represents a cyclic shift of the input sequence. The first row is the sequence itself and subsequent rows are created by shifting elements of the previous row to the right in a circular manner. The cyclic structure of circulant matrices makes them very useful for certain applications in signal processing and linear algebra.
Circulant matrices are used in signal processing, image filtering, and convolution problems. They well represent linear time-invariant systems and appear very extensively in Fourier analysis since circulants are diagonalized by the Discrete Fourier Transform.
This approach is unlikely to produce errors unless the input is invalid, such as non-1D data. To obtain reliable results, ensure that the input c is a valid 1D sequence.
This circulant() method can be combined with FFT() (Fast Fourier Transform) in order to efficiently compute convolutions, therefore, it is powerful for signal and image processing tasks.
Syntax
The syntax for the Scipy method is as follows −
.circulant(c)
Parameters
This method accepts the following parameters −
c (N,) array_like − 1D array-like sequence that defines the first row of the circulant matrix.
Return Value
A (N, N) ndarray − A square nn circulant matrix, where n is the length of c.
Example 1: Basic Circulant Matrix
The circulant approach constructs a matrix in which each row is a cyclic shift of the input sequence.
In the below code, the input array c=[1,2,3,4] determines the first row of the circulant matrix. The circulant() method accepts this array and returns a square matrix in which the first row is exactly c.
Each subsequent row is a cyclic shift of the previous row; that is, the last element shifts to the front, and all other elements shift one place to the right.
import numpy as np from scipy.linalg import circulant # Input: 1D array c = [1, 2, 3, 4] # Generate the circulant matrix C = circulant(c) print("Circulant Matrix:\n", C)
When we run above program, it produces following result
Circulant Matrix: [[1 4 3 2] [2 1 4 3] [3 2 1 4] [4 3 2 1]]
Example 2: Circulant Matrix and FFT for Efficient Convolution
The circulant() method creates a circulant matrix from a periodic signal represented by the array signal=[1,1,1,1]. The circulant matrix models the signal's cyclic nature, with each row representing a cyclic shift in the input sequence.
The circulant matrix's Fourier Transform is then computed by using the fft() function to its columns. This transformation encodes the signal in the frequency domain, allowing for efficient convolution processes. The output gives the converted data, which can be used for further analysis, including filtering or signal reconstruction.
import numpy as np from scipy.linalg import circulant from scipy.fft import fft # Input: Signal array signal = [1, -1, 1, -1] # Generate the circulant matrix C = circulant(signal) # Compute the FFT of the circulant matrix fft_result = fft(C, axis=0) print("FFT of Circulant Matrix:\n", fft_result)
Following is an output of the above code
FFT of Circulant Matrix: [[ 0.-0.j 0.-0.j 0.-0.j 0.-0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 4.-0.j -4.-0.j 4.-0.j -4.-0.j] [ 0.-0.j 0.-0.j 0.-0.j 0.-0.j]]
Example 3: Solving Linear Systems with Circulant Matrices
In the code below, the input array c=[4,1,0] creates a circulant matrix C by using circulant() method, while the vector b=[1,2,3] represents the right-hand side of the equation Cx=b. The solve() method uses the circulant matrix's cyclic properties to efficiently compute the solution vector (x). The output shows x, which satisfies the linear system.
import numpy as np from scipy.linalg import circulant, solve # Input: Circulant matrix and right-hand side vector c = [4, 1, 0] b = [1, 2, 3] # Generate the circulant matrix C = circulant(c) # Solve the linear system Cx = b solution = solve(C, b) print("Solution of the Linear System:\n", solution)
Output of the above code is as follows
Solution of the Linear System: [0.09230769 0.47692308 0.63076923]