I need to replace einsum operation with standard numpy operations in the following code:
import numpy as np
a = np.random.rand(128, 16, 8, 32)
b = np.random.rand(256, 8, 32)
output = np.einsum('aijb,rjb->ira', a, b)
Thanks in advance for your help.
One option would be to align to a similar shape and broadcast multiply, then
sum
and reorder the axes:But this is much less efficient as it's producing a large intermediate (shape
(128, 16, 256, 8, 32)
):Shapes: