Open
Description
Currently
In [1]: a = np.ones(10)[::2]
In [2]: a.flags
Out[2]:
C_CONTIGUOUS : False
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
In [3]: b = np.array(a.flat, copy=False)
In [4]: a.flags
Out[4]:
C_CONTIGUOUS : False
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : False
ALIGNED : True
UPDATEIFCOPY : False
The reason is that a.flat.__array__
is called which returns a new array with UPDATEIFCOPY and locks a
by clearing the WRITEABLE flag. Because b hangs onto a reference of the uncopied array, it does not get deallocated, hence does not re-enable the WRITEABLE flag.
Whether this is a bug or a feature is debatable, but given the usual use of asarray
(copy=False
), I think that a copy of the array should be made when UPDATEIFCOPY is set.