nlcpy.ma.make_mask

nlcpy.ma.make_mask(m, copy=False, shrink=True, dtype=<class 'numpy.bool_'>)[source]

Creates a boolean mask from an array.

Returns m as a boolean mask, creating a copy if necessary or requested. The function can accept any sequence that is convertible to integers, or nomask. Does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True.

Parameters
marray_like

Potential mask.

copybool, optional

Whether to return a copy of m (True) or m itself (False).

shrinkbool, optional

Whether to shrink m to nomask if all its values are False.

dtypedtype, optional

Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool). If the dtype is flexible, each field has a boolean dtype. This is ignored when m is nomask, in which case nomask is always returned.

Returns
resultndarray

A boolean mask derived from m.

Examples

>>> import nlcpy as vp
>>> import nlcpy.ma as ma
>>> m = [True, False, True, True]
>>> ma.make_mask(m)
array([ True, False,  True,  True])
>>> m = [1, 0, 1, 1]
>>> ma.make_mask(m)
array([ True, False,  True,  True])
>>> m = [1, 0, 2, -3]
>>> ma.make_mask(m)
array([ True, False,  True,  True])

Effect of the shrink parameter.

>>> m = vp.zeros(4)
>>> m
array([0., 0., 0., 0.])
>>> ma.make_mask(m)
False
>>> ma.make_mask(m, shrink=False)
array([False, False, False, False])