KRON

Computes the Kronecker product, often denoted by \otimes. If A is an m \times n matrix and B is a p \times q matrix, then the Kronecker product A \otimes B is an mp \times nq block matrix.

Excel Usage

=KRON(matrix_a, matrix_b)
  • matrix_a (list[list], required): First input matrix.
  • matrix_b (list[list], required): Second input matrix.

Returns (list[list]): 2D array representing the Kronecker product.

Example 1: Kronecker product of two 2x2 identity matrices

Inputs:

matrix_a matrix_b
1 0 1 0
0 1 0 1

Excel formula:

=KRON({1,0;0,1}, {1,0;0,1})

Expected output:

Result
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Example 2: Kronecker product with a scalar

Inputs:

matrix_a matrix_b
2 1 2
3 4

Excel formula:

=KRON({2}, {1,2;3,4})

Expected output:

Result
2 4
6 8
Example 3: Kronecker product of 2x3 and 2x1 matrices

Inputs:

matrix_a matrix_b
1 2 3 2
4 5 6 3

Excel formula:

=KRON({1,2,3;4,5,6}, {2;3})

Expected output:

Result
2 4 6
3 6 9
8 10 12
12 15 18
Example 4: Kronecker product with positive and negative values

Inputs:

matrix_a matrix_b
1 -1 3 4
0 2

Excel formula:

=KRON({1,-1;0,2}, {3,4})

Expected output:

Result
3 4 -3 -4
0 0 6 8

Python Code

import numpy as np
from scipy.linalg import kron as scipy_kron

def kron(matrix_a, matrix_b):
    """
    Compute the Kronecker product of two matrices.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.kron.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        matrix_a (list[list]): First input matrix.
        matrix_b (list[list]): Second input matrix.

    Returns:
        list[list]: 2D array representing the Kronecker product.
    """
    try:
        def to2d(x):
            return [[x]] if not isinstance(x, list) else x

        matrix_a = to2d(matrix_a)
        matrix_b = to2d(matrix_b)

        if not isinstance(matrix_a, list) or not matrix_a or not all(isinstance(row, list) for row in matrix_a):
            return "Error: matrix_a must be a non-empty 2D list"
        if not isinstance(matrix_b, list) or not matrix_b or not all(isinstance(row, list) for row in matrix_b):
            return "Error: matrix_b must be a non-empty 2D list"
        if any(len(row) == 0 for row in matrix_a):
            return "Error: matrix_a rows must be non-empty"
        if any(len(row) == 0 for row in matrix_b):
            return "Error: matrix_b rows must be non-empty"
        if len({len(row) for row in matrix_a}) != 1:
            return "Error: matrix_a must have consistent row lengths"
        if len({len(row) for row in matrix_b}) != 1:
            return "Error: matrix_b must have consistent row lengths"

        try:
            a = np.array(matrix_a, dtype=float)
            b = np.array(matrix_b, dtype=float)
        except (ValueError, TypeError):
            return "Error: matrix inputs must contain numeric values"

        if not np.all(np.isfinite(a)) or not np.all(np.isfinite(b)):
            return "Error: matrix inputs must contain only finite numbers"

        try:
            res = scipy_kron(a, b)
        except Exception as e:
            return f"Error: {str(e)}"

        return res.tolist()

    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

First input matrix.
Second input matrix.