[Numpy-discussion] Efficient numpy slicing for a "sliding window approach".
Fri Feb 20 22:55:43 CST 2009
On Sat, Feb 21, 2009 at 1:46 PM, Nicolas Pinto <firstname.lastname@example.org> wrote:
> Dear all,
> I'm trying to optimize the code below and I was wondering if there is an
> efficient method that could reduce the numpy slicing overheard without going
> with cython. Is there anyway I could use mgrid to get a matrix with all my
> "windows" and then do a large matrix multiply instead?
If you only care about removing the two loops for the per-window
processing, Anne Archibald and Robert Kern wrote a very useful
function, segment_axis, which is like the matlab buffer function on
steroids, using numpy stride tricks (to avoid copies in many cases). I
think that would do everything you want, right ? I use it a lot in my
own code, it may be worth being included in numpy or scipy proper.
More information about the Numpy-discussion