I've got an array (L) of shape (2,2) and an array (W) of shape (2, 5, 3) I'd like to know what is the operation of that does a dot product for each element in axis 2. the result should be of shape (2,5,3). I've tried:
np.malmul(L, W)
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0
and
np.tensordot(L, W)
ValueError: shape-mismatch for sum
both return me an error. The slow non pythonic solution is:
W_corr = []
for i in range(W.shape[-1]):
res_ = L.dot(W[:,:,i])
W_corr.append(res_)
W_corr = np.moveaxis(np.array(W_corr), 0, -1)
But I'm sure there's a better way. Any idea?