[Numpy-discussion] speeding up the following expression

Geoffrey Zhu zyzhu2000 at gmail.com
Sat Nov 12 03:36:38 EST 2011


I am playing with multiple ways to speed up the following expression
(it is in the inner loop):

C[1:(M - 1)]=(a * C[2:] + b * C[1:(M-1)] + c * C[:(M-2)])

where C is an array of about 200-300 elements, M=len(C), a, b, c are scalars.

I played with numexpr, but it was way slower than directly using
numpy. It would be nice if I could create a Mx3 matrix without copying
memory and so I can use dot() to calculate the whole thing.

Can anyone help with giving some advices to make this faster?


More information about the NumPy-Discussion mailing list