[Numpy-discussion] Stride of 2 for correlate()
Anne Archibald
peridot.faceted@gmail....
Tue Feb 5 18:09:04 CST 2008
On 05/02/2008, Chris Finley <cfinley@u.washington.edu> wrote:
> After searching the archives, I was unable to find a good method for
> changing the stride of the correlate or convolve routines. I am doing a
> Daubechies analysis of some sample data, say data = arange(0:80). The
> coefficient array or four floats (say daub_g2[0:4]) is correlated over
> the data. However, the product only needs to be calculated for every
> other data index.
I don't think that correlate or convolve can be made to behave this
way. You can of course just throw away half the values, but I imagine
you'd like it to be reasonably fast (do compare, though, speed
tradeoffs can be surprising, particularly in python). This sort of
thing comes up from time to time, so I took some old code I posted to
scipy-user and put it in the cookbook at
http://www.scipy.org/Cookbook/SegmentAxis . It works by converting
your input array into a (in this case) 4 by n matrix with overlapping
rows (without copying). You can then do what you like with the
resulting array; convolutions just become matrix products. It's
conceivable (though frankly unlikely) that the BLAS acceleration of
matrix multiplication might make this run faster than correlate().
Good luck,
Anne
More information about the Numpy-discussion
mailing list