user308827
user308827

Reputation: 21971

Check if numpy array is masked or not

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

Upvotes: 6

Views: 1964

Answers (1)

user545424
user545424

Reputation: 16189

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

Upvotes: 9

Related Questions