
- 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.pascal() Function
The scipy.linalg.pascal() function generates Pascal matrices which are square matrices based on Pascal's triangle. These matrices are symmetric and positive definite and which often used in combinatorics, algebra and numerical analysis.
Pascal matrices can be created in three forms namely symmetric, lower triangular or upper triangular. The elements in these matrices correspond to binomial coefficients by making them valuable for solving problems involving matrix operations and linear systems.
Syntax
Following is the syntax of the scipy.linalg.pascal() function which is used to find the Pascal matrices −
scipy.linalg.pascal(n, kind='symmetric', exact=True)
Parameters
Following are the parameters of the function scipy.linalg.pascal() −
- n(int): The size of the matrix, which will have dimensions n x n.
-
kind (str, optional): Specifies the type of Pascal matrix:
- symmetric: Creates a symmetric Pascal matrix which is the default.
- lower: Generates a lower triangular Pascal matrix.
- upper: Produces an upper triangular Pascal matrix.
- exact (bool, optional): If this parameter set to True then the matrix elements are returned as integers. Otherwise, they are returned as floating-point numbers which is default value.
Return Value
This function returns an n x n Pascal matrix in the specified format.
Symmetric Pascal Matrix
A Symmetric Pascal Matrix is a square matrix where each element is derived from Pascal's triangle. The elements of the matrix are positive integers and the matrix is symmetric which means it is equal to its transpose. Following is the representation of the symmetric Pascal matrix of size n x n −
P[i,j]=C(i+j,j)
Following is the example of the 4 x 4 Pascal Matrix created with the help of the scipy.linalg.pascal() function −
from scipy.linalg import pascal # Generate a 4x4 symmetric Pascal matrix matrix = pascal(4) # Display the matrix print(matrix)
Following is the output of the function scipy.linalg.pascal() which creates the Symmetric pascal triangular matrix −
[PS D:\Tutorialspoint> python sample.py [[ 1 1 1 1] [ 1 2 3 4] [ 1 3 6 10] [ 1 4 10 20]]
Lower Triangular Pascal Matrix
A Lower Triangular Pascal Matrix is a lower triangular matrix where each element is derived from Pascal's triangle. The elements of the matrix are binomial coefficients and it is lower triangular, meaning that all elements above the main diagonal are zero. A lower triangular Pascal matrix of size n x n the matrix can be represented as follows −
L[i,j]=C(i,j) forij and L[i,j]=0 fori<j
This example shows how to create a 5x5 lower triangular Pascal matrix by using the scipy.linalg.pascal() function −
from scipy.linalg import pascal # Generate a 5x5 lower triangular Pascal matrix lower_matrix = pascal(5, kind='lower') # Display the matrix print(lower_matrix)
Below is the output of the function scipy.linalg.pascal() which creates the lower pascal triangular matrix −
[[1 0 0 0 0] [1 1 0 0 0] [1 2 1 0 0] [1 3 3 1 0] [1 4 6 4 1]]
Pascal Matrix with Integer Elements
A Pascal Matrix with Integer Elements is a matrix in which each element is a binomial coefficient and the matrix is symmetric or lower triangular. This matrix is derived from Pascal's Triangle and its elements are integer values representing combinations.
Here is the example of a 3x3 Pascal matrix with integer elements is generated −
from scipy.linalg import pascal # Create a 3x3 Pascal matrix with integer elements int_matrix = pascal(3, exact=True) # Display the matrix print(int_matrix)
Here is the output of the pascal matrix with integer elements −
[[1 1 1] [1 2 3] [1 3 6]]