Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread josef . pktd
On Fri, Feb 3, 2012 at 4:49 PM, Alan G Isaac wrote: > On 2/3/2012 3:37 PM, josef.p...@gmail.com wrote: >> res = - np.dot(x.T, mass*x) >> res[np.arange(3), np.arange(3)] -= np.trace(res) > > > Nice! > Get some speed gain with slicing: > > res = - np.dot(x.T, mass*x) > res.flat[slice(0,None,4)] -= n

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread Alan G Isaac
On 2/3/2012 3:37 PM, josef.p...@gmail.com wrote: > res = - np.dot(x.T, mass*x) > res[np.arange(3), np.arange(3)] -= np.trace(res) Nice! Get some speed gain with slicing: res = - np.dot(x.T, mass*x) res.flat[slice(0,None,4)] -= np.trace(res) Alan ___

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread josef . pktd
the list at >>>        numpy-discussion-ow...@scipy.org >>> >>> When replying, please edit your Subject line so it is more specific >>> than "Re: Contents of NumPy-Discussion digest..." >>> >>> >>> Today's Topics: >>> >>>   1. Re: Trick for fast (santhu kumar) >>>   2. Re:

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread josef . pktd
: >> >>   1. Re: Trick for fast (santhu kumar) >>   2. Re: Trick for fast (josef.p...@gmail.com) >> >> >> -- >> >> Message: 1 >> Date: Fri, 3 Feb 2012 12:29:26 -0600 >> Fro

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread santhu kumar
s Topics: > > 1. Re: Trick for fast (santhu kumar) > 2. Re: Trick for fast (josef.p...@gmail.com) > > > -- > > Message: 1 > Date: Fri, 3 Feb 2012 12:29:26 -0600 > From: santhu kumar > Subject:

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread josef . pktd
>>   2. Re: Trick for fast (S?ren Gammelmark) >>   3. Re: Trick for fast (Sebastian Berg) >> >> >> -- >> >> Message: 1 >> Date: Fri, 3 Feb 2012 09:10:28 -0500 >> From: josef.p

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread santhu kumar
-17287.5] > [-16755. 0. -17865. ] > [-17287.5 -17865. 0. ]] > [[ 0. -16755. -17287.5] > [-16755. 0. -17865. ] > [-17287.5 -17865. 0. ]] > > Josef > > > > > > ___ > > NumPy-Discussion

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread Sebastian Berg
I guess Einsum is much cleaner, but I already had started with this and maybe someone likes it, this is fully vectorized and uses a bit of funny stuff too: # The dot product(s), written using broadcasting rules: a = -(x.reshape(-1,1,3) * x[...,None]) # Magic, to avoid the eye thing, takes all dia

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread Søren Gammelmark
What about this? A = einsum("i,ij->", mass, x ** 2) B = einsum("i,ij,ik->jk", mass, x, x) I = A * eye(3) - B /Søren On 3 February 2012 15:10, wrote: > On Fri, Feb 3, 2012 at 8:44 AM, Alan G Isaac wrote: > > On 2/3/2012 5:16 AM, santhu kumar wrote: > >> x = nX3 vector. > >> mass = nX1 vector >

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread josef . pktd
On Fri, Feb 3, 2012 at 8:44 AM, Alan G Isaac wrote: > On 2/3/2012 5:16 AM, santhu kumar wrote: >> 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)) >> > > > Thi

Re: [Numpy-discussion] Trick for fast

2012-02-03 Thread Alan G Isaac
On 2/3/2012 5:16 AM, santhu kumar wrote: > 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)) > This should buy you a bit. xdot = (x*x).sum(axis=1) for (massi,xi,xd

[Numpy-discussion] Trick for fast

2012-02-03 Thread santhu kumar
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