If I have a (possibly multidimensional) Python list where each element is one of True, False, or ma.masked, what's the idiomatic way of turning this into a masked numpy array of bool?
Example:
>>> print(somefunc([[True, ma.masked], [False, True]]))
[[True --]
[False True]]
A masked array has to attributes,
dataandmask:That starts without anything masked. Then as you suggest, assigning
np.ma.maskedto an element masks the slot:Here the
arr.maskhas been changed from scalarFalse(applying to the whole array) to a boolean array ofFalse, and then the selected item has been changed toTrue.arr.datahasn't changed:Looks like this change to
arr.maskoccurs indata.__setitem__at:It checks if the assignment values is this special constant,
np.ma.masked, and it makes the full mask, and assignsTrueto an element.