tensor product of matrices in Numpy/python

jason picture jason · Nov 21, 2013 · Viewed 9k times · Source

Is there a numpy function that does tensor product of two matrices ? That creates a 4x4 product matrix of two 2x2 matrices?

Answer

jengel picture jengel · Jul 18, 2014

I believe what you're looking for is the Kronecker product

http://docs.scipy.org/doc/numpy/reference/generated/numpy.kron.html#numpy.kron

Example:

>>> np.kron(np.eye(2), np.ones((2,2)))
array([[ 1.,  1.,  0.,  0.],
       [ 1.,  1.,  0.,  0.],
       [ 0.,  0.,  1.,  1.],
       [ 0.,  0.,  1.,  1.]])