[Numpy-discussion] Proposed X.flat solution

Rick White rlw at stsci.edu
Fri Feb 18 11:32:21 CST 2005


On Fri, 18 Feb 2005, Travis Oliphant wrote:

> O.K.  here is my X.flat solution.
>
> I've decided to make use of the fancy-new, numarray-inspired idea of the
> UPDATEIFCOPY flag for array creation.  Basically, X.flat will create a
> new array if X is discontiguous but with the UPDATEIFCOPY flag set so
> that upon destruction the contents will get copied back to X.
>
> So, it will seem like the X.flat array is updating the original array
> (provided it get's dereferenced someday (which it should because you
> rarely) keep references to X.flat unless you really meant ravel(X).
>
> This is the simplest solution.  It's not quite as fancy as the indexable
> iterator (which could still be implemented at some point) but it lets me
> move forward.

Hmm.  It seems to me that if it is not a live view you can run into
serious problems.  What happens if you do this:

a = zeros((10,10))
b = a[::2,::2].flat
b[4] = 1
a[0,8] = 2
del b

Doesn't your behavior lead to a[0,8] being overwritten to 1 by the copy
back from b?





More information about the Numpy-discussion mailing list