[Numpy-discussion] Trick for fast
Alan G Isaac
alan.isaac at gmail.com
Fri Feb 3 08:44:54 EST 2012
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) in zip(mass.flat,x,xdot):
temp = -np.outer(xi,xi)
temp.flat[slice(0,None,4)] += xdoti
inert += massi*temp
Alan Isaac
More information about the NumPy-Discussion
mailing list