I need to do many cycles of the following type
for i in range(len(a)): for j in range(i+1): c[i] += a[j]*b[ij]
where a and b are short arrays (of the same size as between 10 and 50). This can be done effectively using convolution:
import numpy as np np.convolve(a, b)
However, this gives me a full convolution (i.e. the vector is too long compared to the for loop above). If I use the "same" option in convolve, I get the center part, but what I want is the first part. Of course, I can chop off what I do not need from the full vector, but I would like to get rid of unnecessary calculation time, if possible. Can anyone suggest a better loop vector?
source share