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

Gregorio Bastardo gregorio.bastardo at gmail.com
Mon Jul 15 04:04:46 EDT 2013


Hi Pierre,

> 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

Thanks, it works perfectly =) Sorry, probably have overlooked this
simple solution, tried to set x.data and x.mask directly. I noticed
that this only protects the data, so mask also has to be set to
read-only or be hardened to avoid accidental (un)masking.

Gregorio



More information about the NumPy-Discussion mailing list