numpy.ma.is_mask()

numpy.ma.is_mask(m) [source]

Return True if m is a valid, standard mask.

This function does not check the contents of the input, only that the type is MaskType. In particular, this function returns False if the mask has a flexible dtype.

Parameters:

m : array_like

Array to test.

Returns:

result : bool

True if m.dtype.type is MaskType, False otherwise.

See also

isMaskedArray
Test whether input is an instance of MaskedArray.

Examples

1
2
3
4
5
6
7
8
9
10
>>> import numpy.ma as ma
>>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> m
masked_array(data = [-- 1 -- 2 3],
      mask = [ True False  True False False],
      fill_value=999999)
>>> ma.is_mask(m)
False
>>> ma.is_mask(m.mask)
True

Input must be an ndarray (or have similar attributes) for it to be considered a valid mask.

1
2
3
4
5
6
7
8
>>> m = [False, True, False]
>>> ma.is_mask(m)
False
>>> m = np.array([False, True, False])
>>> m
array([FalseTrue, False], dtype=bool)
>>> ma.is_mask(m)
True

Arrays with complex dtypes don?t return True.

1
2
3
4
5
6
7
8
9
10
11
>>> dtype = np.dtype({'names':['monty', 'pithon'],
                      'formats':[np.bool, np.bool]})
>>> dtype
dtype([('monty', '|b1'), ('pithon', '|b1')])
>>> m = np.array([(True, False), (False, True), (True, False)],
                 dtype=dtype)
>>> m
array([(True, False), (False, True), (True, False)],
      dtype=[('monty', '|b1'), ('pithon', '|b1')])
>>> ma.is_mask(m)
False
doc_NumPy
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.