Skip to content

Memo on `np.ndarray` and `np.ma.masked_array` types

Romain Hugonnet edited this page Sep 5, 2022 · 1 revision

Need to test the input of a function to adapt its behaviour to either a classic np.ndarray or a np.ma.masked_array?

Beware, as np.ma.masked_array is a subclass of np.ndarray, and so isinstance(arr, np.ndarray) will return True for both.

To check if the input array is a classic numpy array which is not masked, one can write:

isinstance(arr, np.ndarray) and not np.ma.is_masked(arr)