- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Get the Kronecker product of two arrays in Python

To get the Kronecker product of two arrays, use the numpy.kron() method in Python Numpy. Compute the Kronecker product, a composite array made of blocks of the second array scaled by the first.

The function assumes that the number of dimensions of a and b are the same, if necessary, prepending the smallest with ones. If a.shape = (r0,r1,..,rN) and b.shape = (s0,s1,...,sN), the Kronecker product has shape (r0*s0, r1*s1, ..., rN*SN). The elements are products of elements from a and b, organized explicitly by −

kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN]

## Steps

At first, import the required libraries −

import numpy as np

Creating two numpy arrays using the array() method −

arr1 = np.array([1, 10, 100]) arr2 = np.array([5, 6, 7])

Display the arrays −

print("Array1...\n",arr1) print("\nArray2...\n",arr2)

Check the Dimensions of both the arrays −

print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim)

Check the Shape of both the arrays −

print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape)

To get the Kronecker product of two arrays, use the numpy.kron() method in Python −

print("\nResult (Kronecker product)...\n",np.kron(arr1, arr2))

## Example

import numpy as np # Creating two numpy arrays using the array() method arr1 = np.array([1, 10, 100]) arr2 = np.array([5, 6, 7]) # Display the arrays print("Array1...\n",arr1) print("\nArray2...\n",arr2) # Check the Dimensions of both the array print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim) # Check the Shape of both the array print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape) # To get the Kronecker product of two arrays, use the numpy.kron() method in Python Numpy print("\nResult (Kronecker product)...\n",np.kron(arr1, arr2))

## Output

Array1... [ 1 10 100] Array2... [5 6 7] Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (3,) Shape of Array2... (3,) Result (Kronecker product)... [ 5 6 7 50 60 70 500 600 700]

- Related Articles
- Get the Kronecker product of two One-Dimensional Arrays in Python
- Get the Kronecker product of two arrays with different dimensions in Python
- Get the Kronecker product of arrays with 4D and 3D dimensions in Python
- Get the Outer product of two arrays in Python
- Get the Inner product of two arrays in Python
- Get the Outer product of two multidimensional arrays in Python
- Get the Inner product of two multi-dimensional arrays in Python
- Get the Inner product of two One-Dimensional arrays in Python
- Get the Outer product of two One-Dimensional arrays in Python
- Return the cross product of two (arrays of) vectors in Python
- Return the multiple vector cross product of two (arrays of) vectors in Python
- Matrix product of two arrays in Numpy
- Return the cross product of two (arrays of) vectors with different dimensions in Python
- Return the inner product of two masked arrays in Numpy
- Return the dot product of two masked arrays in Numpy