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 =
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,xdoti)
On Fri, Feb 3, 2012 at 8:44 AM, Alan G Isaac alan.is...@gmail.com 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))
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, josef.p...@gmail.com wrote:
On Fri, Feb 3, 2012 at 8:44 AM, Alan G Isaac alan.is...@gmail.com wrote:
On 2/3/2012 5:16 AM, santhu kumar wrote:
x = nX3
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
mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120203/d1faa546/attachment-0001.html
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120203/d1faa546
Hi Josef,
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.
(http://en.wikipedia.org/wiki/Moment_of_inertia#Moment_of_inertia_tensor)
So the diagonals are not actually zeros but would have z^2 + y^2 ..
The reason which
Is there a method that gives an array of all the array indices of a
masked array where the mask is True? I've been looking through the docs
and don't see it yet...
Thanks
Howard
--
Howard Lander mailto:how...@renci.org
Senior Research Software Developer
Renaissance Computing Institute (RENCI)
numpy.where(x.mask) should do it.
-=- Olivier
Le 3 février 2012 14:02, Howard how...@renci.org a écrit :
Is there a method that gives an array of all the array indices of a
masked array where the mask is True? I've been looking through the docs and
don't see it yet...
Thanks
Howard
--
Indeed it does!
Thanks very much. I was not aware of the numpy where command.
Howard
On 2/3/12 2:17 PM, Olivier Delalleau wrote:
numpy.where(x.mask) should do it.
-=- Olivier
Le 3 février 2012 14:02, Howard how...@renci.org
mailto:how...@renci.org a écrit :
Is there a method that
On Fri, Feb 3, 2012 at 1:58 PM, santhu kumar mesan...@gmail.com wrote:
Hi Josef,
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.
(http://en.wikipedia.org/wiki/Moment_of_inertia#Moment_of_inertia_tensor)
So the
On Fri, Feb 3, 2012 at 2:33 PM, josef.p...@gmail.com wrote:
On Fri, Feb 3, 2012 at 1:58 PM, santhu kumar mesan...@gmail.com wrote:
Hi Josef,
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.
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
___
On Fri, Feb 3, 2012 at 4:49 PM, Alan G Isaac alan.is...@gmail.com 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)
15 matches
Mail list logo