Is there a numpy function that does tensor product of two matrices ? That creates a 4x4 product matrix of two 2x2 matrices?
To compute the tensor dot product, use the numpy. tensordot() method in Python. The a, b parameters are Tensors to “dot”. The axes parameter, integer_like If an int N, sum over the last N axes of a and the first N axes of b in order.
Tensordot (also known as tensor contraction) sums the product of elements from a and b over the indices specified by axes . This operation corresponds to numpy. tensordot(a, b, axes) . Example 1: When a and b are matrices (order 2), the case axes=1 is equivalent to matrix multiplication.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With