How can I calculate this product without a loop? I think I need to use numpy.tensordot but I can’t seem to set it up correctly. Here’s the loop version:
import numpy as np
a = np.random.rand(5,5,3,3)
b = np.random.rand(5,5,3,3)
c = np.zeros(a.shape[:2])
for i in range(c.shape[0]):
for j in range(c.shape[1]):
c[i,j] = np.sum(a[i,j,:,:] * b[i,j,:,:])
(The result is a numpy array c of shape (5,5))
I’ve lost the plot. The answer is simply
or on one line