I have 2 arrays x and y with shapes (2, 3, 3), respectively, (3, 3). I want to compute the dot product z with shape (2, 3) in the following way:
x = np.array([[[a111, a121, a131], [a211, a221, a231], [a311, a321, a331]],
[[a112, a122, a132], [a212, a222, a232], [a312, a322, a332]]])
y = np.array([[b11, b12, b13], [b21, b22, b23], [b31, b32, b33]])
z = np.array([[a111*b11+a121*b12+a131*b13, a211*b21+a221*b22+a231*b23, a311*b31+a321*b32+a331*b33],
[a112*b11+a122*b12+a132*b13, a212*b21+a222*b22+a232*b23, a312*b31+a322*b32+a332*b33]])
Any ideas on how to do this in a vectorized way?
On the sum-reductions shown in the question, it seems the reduction is along the last axis, while keeping the second axis of
xaligned with the first axis ofy. Because of that requirement of axis-alignment, we can usenp.einsum. Thus, one vectorized solution would be -Sample run -