[Numpy-discussion] Trick for fast

Alan G Isaac alan.isaac@gmail....
Fri Feb 3 15:49:54 CST 2012


On 2/3/2012 3:37 PM, josef.pktd@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



More information about the NumPy-Discussion mailing list