
- 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 - hankel() Function
The scipy.linalg.hankel() method generates a Hankel matrix which has equal anti-diagonals, and the first column is defined by array c and the final row by array r. For constant anti-diagonals, if the last element of c is different from the first element of r, it is substituted with the last element of c. In case r is not defined, then it is an array of zeros in the shape of c.
Hankel matrices are applied to model systems that are described by well-defined structured patterns in signal processing, control systems, and time series analysis.
Errors may arise if the input c is not a 1D array, or if r is provided but has incompatible dimensions. Using extremely big arrays may result in considerable memory consumption and performance difficulties.
The Hankel matrix can be applied with eigenvalue computations such as scipy.linalg.eig() to study the stability of systems and matrix decompositions by using SVD like scipy.linalg.svd(), where it applies dimensionality reduction in signal processing.
Syntax
The syntax for the SciPy hankel() method is as follows −
.hankel(c, r=None)
Parameters
This method accepts the following parameters −
c (array_like) − A 1D array specifying the first column of the Hankel matrix.
r (array_like, optional) − A 1D array specifying the last row of the Hankel matrix. If not provided, r defaults to c.
Return Value
H (ndarray) − A 2D Hankel matrix of size (m,n), where m is the length of c and n is the length of r. The elements are constructed such that H[i,j]=c[i+j] if i+j < m, otherwise r[i+jm+1].
Example 1
This code demonstrates how to create a Hankel matrix using the hankel() method. The input array c = [1, 2, 3, 4] is the first column of the matrix. Since the last row (r) is not defined, the process assumes that it is the reverse of c. The resulting matrix is constructed such that every increasing diagonal from top-left to bottom-right contains the same value.
from scipy.linalg import hankel # First column of the Hankel matrix c = [1, 2, 3, 4] # Generate a basic Hankel matrix matrix = hankel(c) print("Hankel Matrix:") print(matrix)
When we run above program, it produces following result
Hankel Matrix: [[1 2 3 4] [2 3 4 0] [3 4 0 0] [4 0 0 0]]
Example 2
This code creates a Hankel matrix by using the method hankel() and first column c = [1, 2, 3], the last row is r = [4, 5, 6]. It is designed in such a way that each diagonal (from top-left to bottom-right) is identical. It begins with c filling the diagonals with components of r, and the last component of r will be reused whenever necessary.
The resulting matrix begins with c along the diagonals starting with the first column, ending in r. So for example, the first row is the concatenation of c[0], which is 1, and all elements of r, and the subsequent rows begin with the next element of c and then continue diagonally. The outcome is that this is structured similarly to the input.
from scipy.linalg import hankel # First column and last row c = [1, 2, 3] r = [4, 5, 6] matrix = hankel(c, r) print("Hankel Matrix:") print(matrix)
Following is an output of the above code
Hankel Matrix: [[1 2 3] [2 3 5] [3 5 6]]
Example 3
This example demonstrates how to compute the eigenvalues of a Hankel matrix in order to analyze its spectral properties. The matrix is generated with c = [1, 2, 3, 4] as the first column and r = [5, 6, 7, 8] as the last row. The scipy.linalg.eig() function computes the eigenvalues, which contain information about the stability and spectral properties of the matrix.
from scipy.linalg import hankel, eig c = [1, 2, 3, 4] r = [5, 6, 7, 8] matrix = hankel(c, r) # Compute eigenvalues eigenvalues, _ = eig(matrix) print("Hankel Matrix:") print(matrix) print("\nEigenvalues:") print(eigenvalues)
Output of the above code is as follows
Hankel Matrix: [[1 2 3 4] [2 3 4 6] [3 4 6 7] [4 6 7 8]] Eigenvalues: [19.17433156+0.j -1.38699959+0.j -0.34011158+0.j 0.55277961+0.j]