How to multiply a vector by an array/matrix element-wise in numpy?
With a
and v
as the two arrays, few approaches could be suggested -
a*v[:,None,None,None]a*v.reshape(-1, *[1]*3)(a.T * v).Tnp.einsum('i...,i->i...', a, v)
With a
and v
as the two arrays, few approaches could be suggested -
a*v[:,None,None,None]a*v.reshape(-1, *[1]*3)(a.T * v).Tnp.einsum('i...,i->i...', a, v)