Is there a numpy function that does tensor product of two matrices ? That creates a 4x4 product matrix of two 2x2 matrices?
tensor product of matrices in Numpy/python
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.]])
If you're looking for tensor product, then it can be achieved by numpy.
import numpy as np
A = np.array([[1,3], [4,2]])
B = np.array([[2,1], [5,4]])
np.tensordot(A, B, axes=0)
Three common use cases are:
axes = 0 : tensor product
axes = 1 : tensor dot product
axes = 2 : (default) tensor double contraction
© 2022 - 2024 — McMap. All rights reserved.