[Numpy-discussion] numpy ring buffer

Sebastian Berg sebastian at sipsolutions.net
Mon May 6 05:50:29 EDT 2013


On Mon, 2013-05-06 at 11:39 +0200, 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):
> 
> In [209]: np.__version__
> Out[209]: '1.6.2'
> 
> In [210]: v1 = np.arange(10)
> 
> In [211]: v1.flags['OWNDATA']
> Out[211]: True
> 
> In [212]: v2 = np.roll(v1, -1)
> 
> In [213]: v2.flags['OWNDATA']
> Out[213]: False
> 

Don't trust owndata in that regard... since it returns a view, but a
view into a copy. For example if you have subclasses that can be very
common. Try np.may_share_memory(v1, v2) for example.

- Sebastian

> 
> Cheers,
> Daniele
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 





More information about the NumPy-Discussion mailing list