I want to do some intensive computations with numpy, and I'm
struggling a bit to find myyyyy wayyyyyy. Here is the problem :
m and d are two matrices :
m.shape = (x,y,a,b)I want to return
d.shape = (a,b)
i.shape = (x,y)with
i[x,y] = sum(m[x,y] * d)I already found that
m[:,:] * dwill give me a matrix of shape (x,y,a,b) containing the products.
Now I want to sum up on axis 2 and 3. If I do :
(m[:,:] * d).sum(axis=3).sum(axis=2)it seems like I get my result.
I'm wondering : is this syntax leading to efficient computation, or is
there something better ?
thanks
Thomas