[Numpy-discussion] assigning ma.masked. Strange behavior
Scott Sinclair
scott.sinclair.za at gmail.com
Mon Jul 6 02:25:15 EDT 2009
> 2009/7/4 Ben Park <benparkla at gmail.com>:
>
> import numpy as np
> import numpy.ma as ma
>
> # There is no effect on the following assignment of ma.masked.
> a1 = ma.arange(10).reshape((2,5))
> a1.ravel()[np.array([0,2,2])] = ma.masked
In some situations ravel has to return a copy of the data instead of a
view. You're assigning ma.masked to elements of the copy, not tot
elements of a1.
>>> a1 = ma.arange(10).reshape((2,5))
>>> b = a1.ravel()
>>> b[np.array([0,2,2])] = ma.masked
>>> b
masked_array(data = [-- 1 -- 3 4 5 6 7 8 9],
mask = [ True False True False False False False False
False False],
fill_value = 999999)
>>> a1
masked_array(data =
[[0 1 2 3 4]
[5 6 7 8 9]],
mask =
False,
fill_value = 999999)
>>> a1.ravel()[np.array([0,2,2])] = ma.masked
>>> a1
masked_array(data =
[[0 1 2 3 4]
[5 6 7 8 9]],
mask =
False,
fill_value = 999999)
Cheers,
Scott
More information about the NumPy-Discussion
mailing list