Kronecker Product Calculator

By · Last updated:

Kronecker Product Calculator A ⊗ B

Type two matrices, one row per line, with numbers separated by spaces or commas. Any two shapes work, up to 6 × 6 each. You get A ⊗ B, its shape, a block diagram showing where each scaled copy of B lands, and the working for every block.

Examples:

The Kronecker product A ⊗ B is the block matrix you get by multiplying every entry of A by the whole of B, so an m × n matrix and a p × q matrix give an mp × nq result. This Kronecker product calculator returns that matrix, its shape, a block diagram, and trace and determinant checks for square inputs.

What is the Kronecker product?

Take two matrices of any shapes at all. Replace each entry of A with a full copy of B scaled by that entry, and glue the copies together in the same layout A had. That is the whole operation. No dimensions have to agree, which makes it unlike almost every other way of combining two matrices.

The result grows quickly: the row counts multiply and the column counts multiply. Two 2 × 2 matrices give a 4 × 4 matrix, a 2 × 3 with a 3 × 2 gives a 6 × 6, and two 6 × 6 inputs already give 36 × 36 with 1,296 entries.

What is the Kronecker product formula?

\[ A \otimes B = \begin{bmatrix} a_{11}B & \cdots & a_{1n}B \\ \vdots & \ddots & \vdots \\ a_{m1}B & \cdots & a_{mn}B \end{bmatrix} \qquad (A \otimes B)_{(i-1)p+k,\ (j-1)q+l} = a_{ij}\, b_{kl} \]

Here A is m × n with entries \(a_{ij}\), and B is p × q with entries \(b_{kl}\). The index \(i\) runs over the rows of A and \(j\) over its columns; \(k\) and \(l\) do the same for B. The left-hand form shows the blocks. The right-hand form gives the position of a single product: the pair \((i,j)\) picks the block and \((k,l)\) picks the cell inside it.

Worked example: two 2 × 2 matrices

The calculator loads with A = [[1, 2], [3, 4]] and B = [[0, 5], [6, 7]]. A has four entries, so there are four blocks: 1·B, 2·B, 3·B and 4·B.

\[ \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \otimes \begin{bmatrix} 0 & 5 \\ 6 & 7 \end{bmatrix} = \begin{bmatrix} 1B & 2B \\ 3B & 4B \end{bmatrix} = \begin{bmatrix} 0 & 5 & 0 & 10 \\ 6 & 7 & 12 & 14 \\ 0 & 15 & 0 & 20 \\ 18 & 21 & 24 & 28 \end{bmatrix} \]

The top-right block is 2·B = [[0, 10], [12, 14]] and the bottom-left block is 3·B = [[0, 15], [18, 21]]. Tick Also compute B ⊗ A and the first row changes from 0, 5, 0, 10 to 0, 0, 5, 10: the same sixteen numbers, arranged differently.

How is the Kronecker product different from matrix multiplication and the Hadamard product?

Three operations share the word “product” and give three different answers for the same pair of matrices. The ordinary product from the matrix multiplication calculator takes dot products of rows with columns. The element-wise Hadamard product multiplies matching positions. The Kronecker product multiplies every entry by every entry.

Kronecker A ⊗ BMatrix product ABHadamard A ∘ B
Shape requirementNoneColumns of A = rows of BIdentical shapes
Result shapemp × nqm × (columns of B)Same as the inputs
Commutative?NoNoYes
NumPynp.kron(A, B)A @ BA * B
Default exampleThe 4 × 4 matrix above[[12, 19], [24, 43]][[0, 10], [18, 28]]

Which properties of the Kronecker product are worth knowing?

Most of its usefulness comes from a handful of identities that let you work with the small factors instead of the large product. The numbers below use the default A and B, where tr(A) = 5, tr(B) = 7, det(A) = −2 and det(B) = −30.

PropertyIdentityWith the default matrices
Mixed product\((A \otimes B)(C \otimes D) = AC \otimes BD\)With x = (1, 1) and y = (1, 0): Ax = (3, 7), By = (0, 6), and both sides equal (0, 18, 0, 42)
Transpose\((A \otimes B)^{\top} = A^{\top} \otimes B^{\top}\)First row of either side is 0, 6, 0, 18
Trace\(\operatorname{tr}(A \otimes B) = \operatorname{tr}(A)\operatorname{tr}(B)\)0 + 7 + 0 + 28 = 35 = 5 × 7
Determinant\(\det(A \otimes B) = \det(A)^{m}\det(B)^{n}\) for A n × n and B m × m(−2)2 × (−30)2 = 4 × 900 = 3,600
Inverse\((A \otimes B)^{-1} = A^{-1} \otimes B^{-1}\)Exists, because both determinants are non-zero

The mixed-product rule is the one the others lean on. It only requires that the ordinary products AC and BD are defined, and it is the reason the inverse factorises. The transpose rule keeps the order of the factors, unlike the transpose of an ordinary product; you can confirm it by pasting both results into the transpose calculator. In the determinant rule each exponent is the size of the other matrix, which you can check for any square pair with the determinant calculator.

Where is the Kronecker product used in machine learning?

Second-order optimisation (K-FAC). For a fully connected layer with 1,000 inputs and 1,000 outputs, the weight matrix has one million parameters and its block of the Fisher information matrix has 1012 entries. Kronecker-factored approximate curvature approximates that block as a Kronecker product of two 1,000 × 1,000 matrices: the second moment of the layer inputs and the second moment of the back-propagated gradients. Because the inverse of a Kronecker product is the Kronecker product of the inverses, only the two small factors are ever inverted.

Structured covariance. A multi-task Gaussian process often uses the kernel Ktasks ⊗ Kinputs, one matrix describing how tasks relate and one describing how inputs relate. The same pattern appears in matrix-normal models, where a row covariance and a column covariance combine into the covariance of the flattened matrix.

Quantum computing. An operator acting on several qubits is the Kronecker product of the single-qubit operators. Pauli X on the first qubit and Pauli Z on the second is the 4 × 4 matrix X ⊗ Z, and n qubits need 2n × 2n matrices. Gates that entangle, such as CNOT, cannot be written as a single Kronecker product.

Vectorising matrix equations. If vec stacks the columns of a matrix into one long vector, then

\[ \operatorname{vec}(AXB) = (B^{\top} \otimes A)\,\operatorname{vec}(X) \]

This turns a matrix equation such as AXB = C into an ordinary linear system in the entries of X, and it is the standard route to derivatives with respect to a weight matrix. Solving that system directly would call for the inverse of the Kronecker factor, which again splits into two small inverses.

Common mistakes

  • Assuming the order does not matter. A ⊗ B and B ⊗ A contain the same entries but are different matrices in general. They are related by a reordering of rows and columns.
  • Swapping the determinant exponents. For a 2 × 2 matrix A and a 3 × 3 matrix B the rule is det(A)3 × det(B)2, not the other way round.
  • Using the wrong vec convention. The vec identity above stacks columns. NumPy flattens by rows unless you pass order="F"; with row stacking the identity becomes (A ⊗ BT) vec(X).
  • Building the full matrix when you do not need it. The Kronecker product of two 1,000 × 1,000 matrices has 1012 entries, about 8 TB in 64-bit floats. Keep the factors and use the identities.
  • Confusing it with the Hadamard product. The symbols ⊗ and ∘ look similar in handwriting, but the element-wise product needs equal shapes and never changes the size.

How do you compute a Kronecker product in Python?

numpy.kron does it in one call and reproduces the worked example:

import numpy as np

A = np.array([[1, 2], [3, 4]])
B = np.array([[0, 5], [6, 7]])

K = np.kron(A, B)
print(K)
# [[ 0  5  0 10]
#  [ 6  7 12 14]
#  [ 0 15  0 20]
#  [18 21 24 28]]
print(K.shape)                            # (4, 4)
print(np.trace(K))                        # 35
print(round(np.linalg.det(K)))            # 3600
print(np.array_equal(K, np.kron(B, A)))   # False

# vec(AXB) = (B^T kron A) vec(X), stacking columns
X = np.array([[1, 0], [2, 1]])
lhs = (A @ X @ B).flatten(order="F")
rhs = np.kron(B.T, A) @ X.flatten(order="F")
print(lhs, np.array_equal(lhs, rhs))      # [12 24 39 83] True

For large problems avoid forming K at all: apply the factors one after the other, which is what the vec identity lets you do.

Frequently asked questions

Is the Kronecker product commutative?

No. The Kronecker product of A and B and the Kronecker product of B and A have the same shape and the same entries, but the entries sit in different positions. For the default example the first row is 0, 5, 0, 10 in one order and 0, 0, 5, 10 in the other.

What size is the Kronecker product of two matrices?

If A is m by n and B is p by q, the Kronecker product is mp by nq. A 2 by 3 matrix with a 3 by 2 matrix gives a 6 by 6 result, and a 1 by 2 row with a 2 by 1 column gives a 2 by 2 result.

Is the Kronecker product the same as the tensor product?

It is the tensor product of two linear maps written as an ordinary matrix in the standard basis. NumPy shows the difference in layout: kron returns a two-dimensional mp by nq array, while tensordot with axes set to 0 returns a four-dimensional array holding the same products.

How is the Kronecker product related to the outer product?

The outer product of two vectors is a special case. Taking the Kronecker product of a column vector with a row vector gives exactly the outer product matrix, with one row per entry of the first vector and one column per entry of the second.

Related calculators

The linear algebra calculators hub lists every matrix and vector tool on the site. These pair most directly with the Kronecker product: