I have two Nx3 matrices f
and r
, and I want to get this quantity
(f*r).sum()
Sometimes I need to change the sign of some of the columns of r
before that calculation, for example
n=5
f=np.random.rand(n,3)
r=np.random.rand(n,3)
# real calculation
r[:, [0,2]]= -r[:, [0,2]]
got=(f*r).sum()
Is there any numpy trick to make this faster?
Edit:
maybe this?
got = (f * rr).sum(axis=0)
print(-got[0].sum() + got[1].sum() - got[2].sum())