[Numpy-discussion] read-only or immutable masked array

Pierre GM pgmdevlist at gmail.com
Sun Jul 14 09:55:32 EDT 2013


On Jul 13, 2013, at 13:36 , Gregorio Bastardo <gregorio.bastardo at gmail.com> wrote:

> Hi Stéfan,
> 
> Thanks for the suggestion, but it does not protect the array:

Thinking about it, it can't: when `x` is a MaskedArray, `x.data` is just a view of the underlying array as a regular ndarray. As far as I understand, changing the `.flags` of a view doesn't affect the original.

I'm a bit surprised, though. Here's what I tried

>>> np.version.version
<<< 1.7.0
>>> x = np.ma.array([1,2,3], mask=[0,1,0])
>>> x.flags.writeable=False
>>> x[0]=-1
<<< ValueError: assignment destination is read-only

What did you mean by 

>>> array.flags.writeable = False
>>> 
>>> is perfectly fine, but it does not work on ma-s.

? Could you post what you did and what you got?


>>> Moreover, mask
>>> hardening only protects masked elements, and does not raise error (as
>>> I'd expect).

Yes, that's how it supposed to work.


More information about the NumPy-Discussion mailing list