[Numpy-discussion] fiddling the strides of an array

Charles R Harris charlesr.harris at gmail.com
Mon Nov 20 13:56:13 CST 2006


On 11/20/06, A. M. Archibald <peridot.faceted at gmail.com> wrote:
>
> On 19/11/06, A. M. Archibald <peridot.faceted at gmail.com> wrote:
>
> > Well, no, of course not to implement "fiddle". But the application I
> > have in mind I don't think can be done with slicing...
>
> If it helps to motivate what I'm doing, I'm trying to write (have
> written) a function that will take an array and segment it along an
> axis into overlapping pieces with a given length and number of entries
> of overlap. Of course this is easy using reshape and stacking, but
> there's no reason it needs to make a copy, or to occupy a large amount
> of space. I can generate the strides that should be used for such a
> segmented view of an array from the strides of the original array with
> little difficulty, and the program works fine for one-dimensional
> arrays.


Cute!

But if you try to feed it a high-dimensional array,
> ndarray.__new__ often has a fit because it can't convert the array to
> a (contiguous) buffer. I even considered lying to the system and
> marking the array as contiguous, but even apart from being a bad idea
> it doesn't seem to be possible from python.
>
> I've attached the function; its test cases include several that
> trigger the problem (at which point it spits out a warning and just
> copies the array).
>
> The function was suggested on the scipy list by a Matlab escapee as a
> very handy function for signal processing. (Taking FFTs of successive
> overlapped chunks, for example.)


Although I suspect a special purpose FFT would be the thing here. For
piecewise convolution it may also be desireable to zero extend the pieces,
etc.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061120/2e674213/attachment.html 


More information about the Numpy-discussion mailing list