
- 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 - solve_circulant()Function
The scipy.linalg.solve_circulant() function can solve linear systems of the Ax=b form, where A is a circulant matrix. This function can even work on singular and non-singular circulant matrices and it makes use of the Fast Fourier Transform.
This approach is particularly useful when dealing with cyclic or periodic systems, which appear fairly often in image processing and time-series analysis, as well as signal processing. It uses pseudo-inverses to ensure robust solutions should they be needed and works for singular matrices.
Syntax
Following is the syntax of the SciPy solve_circulant() method −
.solve_circulant(c, b, singular='raise', tol=None, caxis=0, baxis=0, outaxis=0)
Parameters
Following is the parameters of solve_circulant() method
c (array_like) − 1D array representing the first row of the circulant matrix
b array_like, shape (n,) or (n, k) − Input equation of Right-hand side.
singular (str, optional) − Specifies behavior for singular matrices
tol (float, optional)− Tolerance for determining singular matrices.
caxis (int, optional) − Axis along which the first column of the circulant matrix is stored in c. Default is 0.
baxis (int, optional) − Axis along which the right-hand side is stored in b. Default is 0.
outaxis (int, optional) − Axis along which the output is returned. Default is 0.
Return Value
x (ndarray) − The solution to the circulant system.
Example 1: Solving a Basic Circulant System
In the below example, we have created a small circulant matrix defined by its first column c. The function solve_circulant() solves the system C x = b.
import numpy as np import scipy.linalg from scipy.linalg import solve_circulant # Define the first column of the circulant matrix c = np.array([4, 1, 2]) # Define the right-hand side vector b = np.array([7, 8, 9]) # Solve the circulant system x = scipy.linalg.solve_circulant(c, b) print("Solution x:", x)
When we run the above program, it produces the following result
Solution x: [0.85714286 1. 1.57142857]
Example 2: Solving a Singular Circulant Matrix
The function solve_circulant() calculates an internal pseudo-inverse when it is solving problems that have singular circulant matrices so as to ensure a least-squares solution, even if the matrix cannot be inverted directly.
The method handles a singular matrix by internally calculating the pseudo-inverse when set with singular=True. This example solves a singular circulant system where direct inversion is not possible.
import numpy as np from scipy.linalg import solve_circulant # Define the first column of a singular circulant matrix c = np.array([2, 1, 1]) b = np.array([5, 5, 5]) # Solve the system with singular=True x = solve_circulant(c, b, singular=True) print("Solution x:", x)
Following is an output of the above code
Solution x: [1.25 1.25 1.25]
Example 3: Combining solve_circulant with FFT
The solve_circulant() method leverages FFT internally, making it ideal for applications involving frequency-domain operations.
This example demonstrates how to solve a circulant system x, and then fft is applied to x to transform it into the frequency domain.
import numpy as np from scipy.linalg import solve_circulant from scipy.fft import fft c = np.array([3, 2, 1]) b = np.array([6, 7, 8]) x = solve_circulant(c, b) # Compute the FFT of the solution to analyze frequency components frequency_spectrum = fft(x) print("Solution x:", x) print("Frequency Spectrum of Solution:", frequency_spectrum)
Following is the output of the above code
Solution x: [0.5 1.5 1.5] Frequency Spectrum of Solution: [ 3.5-0.j -1. +0.j -1. -0.j]