[Numpy-discussion] Trick for fast

santhu kumar mesanthu@gmail....
Fri Feb 3 04:16:52 CST 2012


Hello all,

I have tried to optimize most of my code but this ones seems to be the
major bottleneck as it gets called many times. I have run out of ideas to
make it more faster, can somebody please help me here.

x = nX3 vector.
mass = nX1 vector
inert = zeros((3,3))
for i in range(n):
      ri = x[i,:].reshape(1,3)
      inert = inert + mass[i,]*(sum(ri*ri)*eye(3) - dot(ri.T,ri))

Any pythonic or numpy technique to make it faster. What I can think of is a
sloppy nX9 matrix creation and then performing row wise summation and
reshaping it. But is there any better way.

Thanks
santhosh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120203/e206633d/attachment.html 


More information about the NumPy-Discussion mailing list