I have 2 2D arrays, with 1 axis of the same dimension:
a = np.array(np.arange(6).reshape((2,3)))
b = np.array(np.arange(12).reshape((3,4)))
I want to multiply and broadcast each row of a
with b
, that is
b_r = np.repeat(b[:,:,None], 2, axis=2)
ab = a.T[:,None,:] * b_r
Is it possible to do the broadcasting while avoiding the repeat
? The idea is to avoid unnecessary memory allocation for the repeat
operation.