[Numpy-discussion] speeding up the following expression

josef.pktd@gmai... josef.pktd@gmai...
Sat Nov 12 06:43:57 CST 2011


On Sat, Nov 12, 2011 at 3:36 AM, Geoffrey Zhu <zyzhu2000@gmail.com> wrote:
> Hi,
>
> 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?

looks like a np.convolve(C, [a,b,c])  to me except for the boundary conditions.

Josef


>
> Thanks,
> G
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list