
- 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 - kron() Function
SciPy's linear algebra library has a Kron() function to compute the Kronecker Product also called the tensor product, of two matrices A and B.
The Kronecker product takes each element of the first matrix and multiplies the whole second matrix by it. This operation joins the two original matrices into a bigger one. Scientists often use this method in quantum physics, signal processing, and systems theory.
For matrices A (mn) and B (pq), their Kronecker product A B results in a matrix of dimensions mpnq. To build this final matrix, you multiply each element of A by the entire matrix B.
Syntax
The syntax for the Scipy kron() method is as follows −
.kron(a, b)
Parameters
This method accepts the following parameters −
a − array-like shape(nxm) first input matrix.
b − array-like shape(pxq) second input matrix
Return Value
This method returns the new matrix of the Kronecker product of A and B.
Example 1: Basic Kronecker Product Calculation
This example shows how to use the kron() method. We make two matrices, 'a' and 'b' then figure out their Kronecker product a b with kron().
import numpy as np from scipy.linalg import kron # Define two matrices a and b a = np.array([[3, 2], [4, 1]]) b = np.array([[0, 2], [6, 9]]) # Compute the Kronecker product result = kron(a, b) print("Kronecker product of a and b:") print(result)
When we run above program, it produces following result −
Kronecker product of a and b: [[ 0 6 0 4] [18 27 12 18] [ 0 8 0 2] [24 36 6 9]]
Example 2: Solving Linear System Using Kronecker Product
In the below example we have calculated the Kronecker product (K) of matrices A and B using kron() function. We then use this product to solve a linear system Kz=d. Here, d is the Kronecker product of vectors b and c. To get the solution vector z, we solve the system with np.linalg.solve().
import numpy as np from scipy.linalg import kron A = np.array([[2, 1], [1, 2]]) B = np.array([[1, 0], [0, 1]]) b = np.array([3, 4]) c = np.array([1, 2]) K = kron(A, B) d = np.kron(b, c) # Solve the system (Kron product system) z = np.linalg.solve(K, d) print("Kronecker product matrix (A B):\n", K) print("\nRight-hand side vector (d):", d) print("\nSolution vector (z):", z)
Following is an output of the above code −
Kronecker product matrix (A B): [[2 0 1 0] [0 2 0 1] [1 0 2 0] [0 1 0 2]] Right-hand side vector (d): [3 6 4 8] Solution vector (z): [0.66666667 1.33333333 1.66666667 3.33333333]