I create a numpy masked array with the shrink-option set to False (which should yield a full-sized mask), and then I check the size of the mask:
import numpy as np
import numpy.ma as ma
x = ma.array(range(10),shrink=False)
print 'mask size = ', np.array(x.mask).size
which yields: mask size = 1, i.e., the mask is still the default (shrunk) scalar mask.
Is this a (known) bug?
Update:
It seems that also the option shrink=True does not work properly:
x = ma.array(range(3), mask=True, shrink=True)
x.__setmask__(ma.nomask) # remove the mask (should shrink now)
x.mask.size # returns 3, so mask has not shrunk!
_ = x.shrink_mask() # enforce shrinking
x.mask.size # returns 1, so only now it's OK
There’s a misunderstanding here: the
shrinkoption flag prevents the compression of the mask in operations, not at creation. To get an explicit mask (as a boolean array full ofFalse), use themask=Falseflag at creation instead.Nevertheless, I agree it should be considered a bug. Nice catch.
When no explicit mask is given, the default is
nomask, a special value corresponding tonp.bool_(0): it’s a numpy boolean scalar with a value ofFalse, and like any numpy scalar, ashapeof()and a size of 1.Note the difference between
mask=Falseandmask=nomask:mask=Falsewill create a mask as a ndarray with the same shape as the data but full ofFalse(that’s a shortcut), whilemask=nomaskjust tellnp.mathat the mask is not set (which speeds up computations).