Is there an easy way to check if numpy array is masked or not?
Currently, I do the following to check if marr
is masked or not:
try:
arr = marr.data
except:
arr = marr
A masked array is the combination of a standard numpy. ndarray and a mask. A mask is either nomask , indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.
The mask() method replaces the values of the rows where the condition evaluates to True.
You can use the python function isinstance
to check if an object is an instance of a class.
>>> isinstance(np.ma.array(np.arange(10)),np.ma.MaskedArray)
True
>>> isinstance(np.arange(10),np.ma.MaskedArray)
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With