[Numpy-discussion] Trick for fast
Fri Feb 3 12:58:43 CST 2012
I am unclear on what you want to say, but all I am doing in the code is
getting inertia tensor for a bunch of particle masses.
So the diagonals are not actually zeros but would have z^2 + y^2 ..
The reason which I said 3secs could be misunderstood .. This code is called
many times over a loop and the bulk time is taken in computing this
After code change, the entire loop finishes off in 3 ses.
Thanks for alertness,
On Fri, Feb 3, 2012 at 12:47 PM, <firstname.lastname@example.org> wrote:
> Send NumPy-Discussion mailing list submissions to
> To subscribe or unsubscribe via the World Wide Web, visit
> or, via email, send a message with subject or body 'help' to
> You can reach the person managing the list at
> 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: Trick for fast (email@example.com)
> Message: 1
> Date: Fri, 3 Feb 2012 12:29:26 -0600
> From: santhu kumar <firstname.lastname@example.org>
> Subject: Re: [Numpy-discussion] Trick for fast
> To: email@example.com
> Content-Type: text/plain; charset="iso-8859-1"
> On Fri, Feb 3, 2012 at 1:29 PM, santhu kumar <firstname.lastname@example.org> wrote:
> > Hello all,
> > Thanks for lovely solutions. I have sat on it for some time and wrote it
> > myself :
> > n =x.shape
> > ea = np.array([1,0,0,0,1,0,0,0,1])
> > inert = ((np.tile(ea,(n,1))*((x*x).sum(axis=1)[:,np.newaxis]) -
> > inert.shape = 3,3
> > Does the trick and reduces the time from over 45 secs to 3 secs.
> > I do want to try einsum but my numpy is little old and it does not have
> > Thanks Sebastian (it was tricky to understand your code for me) and Josef
> > (clean).
> Isn't the entire substraction of the first term just to set the
> diagonal of the result to zero.
> It looks to me now just like the weighted dot product and setting the
> diagonal to zero. That shouldn't take 3 secs unless you actual
> dimensions are huge.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion