python - Unmasking an element by assignment in a 2D numpy MaskedArray -


with 1 dimensional numpy maskedarray can assign element unmasks array:

in [183]: x = np.ma.maskedarray(data=np.zeros((2),dtype=float),mask=true)  in [184]: x[0] = 9  in [185]: x out[185]: masked_array(data = [9.0 --],          mask = [false  true],    fill_value = 1e+20) 

with 2 dimensional array, assigning single value not unmask array:

in [186]: x = np.ma.maskedarray(data=np.zeros((2,2),dtype=float),mask=true)  in [187]: x[0][0] = 9  in [188]: x out[188]: masked_array(data =  [[-- --]  [-- --]],              mask =  [[ true  true]  [ true  true]],        fill_value = 1e+20) 

if assign slice, slice gets unmasked

in [189]: x[0] = 9  in [190]: x out[190]: masked_array(data =  [[9.0 9.0]  [-- --]],              mask =  [[false false]  [ true  true]],        fill_value = 1e+20) 

how can assign single value unmask it?

x[0, 0] = 9 

it looks when execute x[0][0] = 9, numpy decouples x[0] temporary's mask x's mask, assignment unmasks x[0] temporary. relevant code in numpy/ma/core.py:

            # unshare mask if necessary avoid propagation             if not self._isfield:                 self.unshare_mask()                 _mask = ndarray.__getattribute__(self, '_mask') 

i don't know why that.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -