What is a tensor product?

The state of a coin can be defined by a vector COIN=(HEADTAIL)\text{COIN} = \begin{pmatrix}\text{HEAD}\\\text{TAIL}\end{pmatrix}. Let's consider the state of one coin to beCOIN1=(0.70.3)\text{COIN}_1 = \begin{pmatrix}0.7 \\ 0.3 \end{pmatrix}; this means that the coin is HEAD\text{HEAD} 70% of the time and TAIL\text{TAIL} 30% of the time. Let's consider another coin with the state COIN2=(0.40.6)\text{COIN}_2 = \begin{pmatrix} 0.4\\0.6 \end{pmatrix}, i.e., it is HEAD\text{HEAD} 50% of the time and TAIL\text{TAIL} 50% of the time—it is an unbiased coin.

How can we define the combined state of a system comprising of COIN1\text{COIN}_1 and COIN2\text{COIN}_2?

Mathematically, composite systems are represented by the following relation:

Relation between the states of two coins
Relation between the states of two coins

Therefore, the state of the above system becomes (0.280.420.120.18)\begin{pmatrix} 0.28\\ 0.42 \\0.12\\0.18 \end{pmatrix}.

Tensor product

In linear algebra, this can be done by computing the tensor product of two vectors. For two vectors vvand ww, their tensor product can be defined as follows:

Here, v1,v2,,vnv_1, v_2, \cdots, v_nare the elements of v.v.

If mm is the dimension of vv, and nn is the dimension of ww, the dimension of vwv\otimes wis m×n.m\times n.

Note: Tensor products are defined on both vectors and matrices.

Code example

In NumPy, the tensor product of two arrays can be evaluated using the kron() function. Let's evaluate the tensor product of the two coin states under consideration:

# Import numpy
import numpy as np
# Define the vectors
coin_1 = np.array([0.7, 0.3])
coin_2 = np.array([0.4, 0.6])
# Evaluate the tensor product
tensor_product = np.kron(coin_1, coin_2)
print(tensor_product)

Here, the kron() function is used for evaluating the tensor product between the two vectors we defined, coin_1 and coin_2.

Copyright ©2024 Educative, Inc. All rights reserved