bundles / numpy latest / numpy / ma / core / make_mask
function
numpy.ma.core:make_mask
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py :1596
Signature
def make_mask ( m , copy = False , shrink = True , dtype = <class 'numpy.bool'> ) Summary
Create a boolean mask from an array.
Extended Summary
Return 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
m: array_likePotential mask.
copy: bool, optionalWhether to return a copy of
m(True) ormitself (False).shrink: bool, optionalWhether to shrink
mtonomaskif all its values are False.dtype: dtype, optionalData-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
misnomask, in which casenomaskis always returned.
Returns
result: ndarrayA boolean mask derived from
m.
Examples
import numpy as np import numpy.ma as ma m = [True, False, True, True] ma.make_mask(m) m = [1, 0, 1, 1] ma.make_mask(m) m = [1, 0, 2, -3] ma.make_mask(m)Effect of the `shrink` parameter.
m = np.zeros(4) m ma.make_mask(m) ma.make_mask(m, shrink=False)Using a flexible `dtype`.
m = [1, 0, 1, 1] n = [0, 1, 0, 0] arr = [] for man, mouse in zip(m, n): arr.append((man, mouse)) arr dtype = np.dtype({'names':['man', 'mouse'], 'formats':[np.int64, np.int64]}) arr = np.array(arr, dtype=dtype) arr ma.make_mask(arr, dtype=dtype)
Aliases
-
numpy.ma.make_mask