[Numpy-discussion] array flags not copied/deepcopied

Nathaniel Smith njs@pobox....
Tue Oct 16 13:22:30 CDT 2012


On Tue, Oct 16, 2012 at 4:36 PM, Byron Blay <byronblay@googlemail.com> wrote:
> Copying / deepcopying an array does not copy the writeable flag:
>
>>>> import numpy
>>>> from copy import deepcopy
>>>> a = numpy.array([1,2,3,4,5])
>>>> a.flags.writeable = False
>>>> b = deepcopy(a)
>>>> b.flags.writeable
> True
>
> Is this a bug?
> Should I raise an issue on github?

I think this is intended? numpy doesn't really think of writeable and
non-writeable arrays as being different sorts of objects;
flags.writeable just records a fact about the underlying memory that
the array refers to. If you make a new copy, then (by definition!) you
get a nice new chunk of freshly allocated memory, and the memory is
writeable.

That said, this might not be the most useful approach. Can you
elaborate on your situation where this is causing a problem?

-n


More information about the NumPy-Discussion mailing list