
- 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 linalg.solveh_banded() Function
The linalg.solveh_banded() function is a matrix with nonzero elements confined to diagonal bands above and below the main diagonal. The upper bandwidth denotes the number of non zero diagonals above the main diagonals above the main diagonal, while the lower bandwidth denotes the number of nonzero diagonals below the main diagonal.
To solve the equation ax = b for x, assuming a is a Hermitian positive-definite banded matrix.
The matrix a is sorted in ab either in lower diagonal or upper diagonal ordered form.
ab[u + i - j, j] == a[i,j] (if upper form; i <= j) ab[ i - j, j] == a[i,j] (if lower form; i >= j)
Example of ab(shape of a is (6,6), u=2):
upper form: * * a02 a13 a24 a35 * a01 a12 a23 a34 a45 a00 a11 a22 a33 a44 a55 lower form: a00 a11 a22 a33 a44 a55 a10 a21 a32 a43 a54 * a20 a31 a42 a53 * *
Syntax
Following is the syntax for the scipy.linalg.solveh_banded() function.
scipy.linalg.solveh_banded(ab, b, overwrite_ab=False, overwrite_b=False, lower=False, check_finite=True)
Parameters
The parameters for the scipy.linalg.solveh_banded() function are listed below −
ab:(u+1,M) This parameter accepts an array that represents a banded matrix.
b: This parameter accepts an array as input, representing the constants of the equation, i.e., the right-hand side of the equation.
overwrite_ab(): This parameter accepts a Boolean data type that discards data in ab to improve performance. The default value is False.
overwrite_b(): This parameter accepts a Boolean data type that discards data in b to improve performance. The default value is False.
lower: This parameter accepts a Boolean data type. If True, it applies only when the data type. If True, it applies only when the data is contained in the lower triangle of a. The default is to use the upper triangle.
check_finite():This parameter accepts a Boolean datatype used to check whether the input matrix contains only finite numbers. Disabling this parameter increases performance,, but when the input matrix has infinities or NaNs, it can result in issues such as crashes or non-termination. The default value is True.
Example 1
This example code passes matrices in Hermitian form to linalg.solveh_banded(), which returns an array that is the solution of the equations. The array that is the solution of the equations. The array ab contains the main diagonal and non-zero diagonals below the main diagonal, utilizing the lower form. This code solves a banded symmetric positive-definite linear system and prints the solution vector x.
import numpy as np from scipy.linalg import solveh_banded ab = np.array([[ 4, 5, 6, 7, 8, 9], [ 2, 2, 2, 2, 2, 0], [-1, -1, -1, -1, 0, 0]]) b = np.array([1, 2, 2, 3, 3, 3]) x = solveh_banded(ab, b, lower=True) print(x)
Output
The result is generated as follows −
[0.03431373, 0.45938375, 0.05602241, 0.47759104, 0.17577031, 0.34733894]
Example 2
In this example code, solve the Hermitian banded system H x = b, where:
[ 8 2-1j 0 0 ] [ 1 ] H = [2+1j 5 1j 0 ] b = [1+1j] [ 0 -1j 9 -2-1j] [1-2j] [ 0 0 -2+1j 6 ] [ 0 ]
In the code below, we place the upper diagonal in the array hb. This code solves a banded Hermitian positive-definite linear system using solveh_banded, where hb is the banded matrix and b is the right-handed side vector. The solution x is then printed.
import numpy as np from scipy.linalg import solveh_banded hb = np.array([[0, 2-1j, 1j, -2-1j], [8, 5, 9, 6 ]]) b = np.array([1, 1+1j, 1-2j, 0]) x = solveh_banded(hb, b) print(x)
Output
The code is generated as follows −
[ 0.07318536-0.02939412j 0.11877624+0.17696461j 0.10077984-0.23035393j -0.00479904-0.09358128j]
Example 3
In this example code, we pass matrices and the check_finite parameter. The check_finite
import numpy as np from scipy.linalg import solveh_banded ab = np.array([[ 4, 5, np.nan, 7, 8, 9], [ 2, 2, 2, 2, 2, 0], [-1, -1, -1, -1, 0, 0]]) b = np.array([1, 2, 2, 3, 3, 3]) x = solveh_banded(ab, b, lower=True,check_finite=True) print(x)
Output
The output is obtained as follows −
Traceback (most recent call last): File "/home/main.py", line 7, inx = solveh_banded(ab, b, lower=True,check_finite=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/scipy/linalg/_basic.py", line 573, in solveh_banded a1 = _asarray_validated(ab, check_finite=check_finite) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/scipy/_lib/_util.py", line 240, in _asarray_validated a = toarray(a) ^^^^^^^^^^ File "/usr/lib/python3/dist-packages/numpy/lib/function_base.py", line 630, in asarray_chkfinite raise ValueError( ValueError: array must not contain infs or NaNs