[Numpy-discussion] numpy ring buffer

Robert Kern robert.kern at gmail.com
Mon May 6 05:57:20 EDT 2013

On Mon, May 6, 2013 at 10:52 AM, Daniele Nicolodi <daniele at grinta.net> wrote:
> On 06/05/2013 11:39, Daniele Nicolodi wrote:
>> On 06/05/2013 11:01, Robert Kern wrote:
>>> np.roll() copies all of the data every time. It does not return a
>>> view.
>> Are you sure about that?  Either I'm missing something, or it returns a
>> view in my testing (with a fairly old numpy, though):
> Ops... Yes, I missed something: np.roll() returns a view, but not a view
> on the original array, which is indeed copied.
> Your method however also copies the data in a temporary buffer for
> operating on it as a single chunk of data.  It just reduces the copy to
> the interesting region of the buffer array.

Yes, but only in the one case where the window overlaps past the end.
The tradeoff depends on the window size and the buffer size.
Alternately, you can write your processing code to work with one or
two chunks, then you don't need to do any copying.

Robert Kern

More information about the NumPy-Discussion mailing list