Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if numpy array is masked or not

Tags:

python

numpy

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
like image 203
user308827 Avatar asked Nov 04 '16 21:11

user308827


People also ask

What is a masked Numpy array?

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.

What is a mask in Python?

The mask() method replaces the values of the rows where the condition evaluates to True.


1 Answers

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
like image 79
user545424 Avatar answered Nov 14 '22 22:11

user545424