[Numpy-discussion] numpy ring buffer

Daniele Nicolodi daniele at grinta.net
Mon May 6 05:52:08 EDT 2013


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.

It looks like there is no way to use numpy to operate on a ring buffer
without copying the data, and in my use case I would like to avoid the
copying.  I'll write it in Cython...

Cheers,
Daniele





More information about the NumPy-Discussion mailing list