[SciPy-user] SciPy-user Digest, Vol 29, Issue 11

Fernando Perez Fernando.Perez at colorado.edu
Fri Jan 6 16:39:23 CST 2006

Travis Oliphant wrote:

> Ultimately this is because you can't tell whether you simply have
> b = a  # We really could resize a because b is just another name for a...
> or  this
> b = a[1:5:2,0:3:2]  # now b is a *view* of a's memory.   If we resize a, 
> then b is really going to be messed up and give us problems. 
> We could distinguish these two using another array flag like (SHAREDATA) 
> or something.

I'm not sure that can work in python:

In [3]: a = N.arange(10)

In [4]: b = a[::2]

a.SHAREDATA is now true

In [5]: del b

a.SHAREDATA is still true, but shouldn't.

There is no way, to my knowledge, of enforcing this correctly.  In a sense, 
SHAREDATA would be a reference counting mechanism for numpy arrays, but Python 
doesn't really give you enough low-level access to do this reliably (remember 
that __del__ methods of objects are NOT guaranteed to run, so even that is not 
an option).



More information about the SciPy-user mailing list