MCPcopy Index your code
hub / github.com/numpy/numpy / make_mask

Function make_mask

numpy/ma/core.py:1607–1695  ·  view source on GitHub ↗

Create a boolean mask from an array. 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 F

(m, copy=False, shrink=True, dtype=MaskType)

Source from the content-addressed store, hash-verified

1605
1606
1607def make_mask(m, copy=False, shrink=True, dtype=MaskType):
1608 """
1609 Create a boolean mask from an array.
1610
1611 Return `m` as a boolean mask, creating a copy if necessary or requested.
1612 The function can accept any sequence that is convertible to integers,
1613 or ``nomask``. Does not require that contents must be 0s and 1s, values
1614 of 0 are interpreted as False, everything else as True.
1615
1616 Parameters
1617 ----------
1618 m : array_like
1619 Potential mask.
1620 copy : bool, optional
1621 Whether to return a copy of `m` (True) or `m` itself (False).
1622 shrink : bool, optional
1623 Whether to shrink `m` to ``nomask`` if all its values are False.
1624 dtype : dtype, optional
1625 Data-type of the output mask. By default, the output mask has a
1626 dtype of MaskType (bool). If the dtype is flexible, each field has
1627 a boolean dtype. This is ignored when `m` is ``nomask``, in which
1628 case ``nomask`` is always returned.
1629
1630 Returns
1631 -------
1632 result : ndarray
1633 A boolean mask derived from `m`.
1634
1635 Examples
1636 --------
1637 >>> import numpy as np
1638 >>> import numpy.ma as ma
1639 >>> m = [True, False, True, True]
1640 >>> ma.make_mask(m)
1641 array([ True, False, True, True])
1642 >>> m = [1, 0, 1, 1]
1643 >>> ma.make_mask(m)
1644 array([ True, False, True, True])
1645 >>> m = [1, 0, 2, -3]
1646 >>> ma.make_mask(m)
1647 array([ True, False, True, True])
1648
1649 Effect of the `shrink` parameter.
1650
1651 >>> m = np.zeros(4)
1652 >>> m
1653 array([0., 0., 0., 0.])
1654 >>> ma.make_mask(m)
1655 False
1656 >>> ma.make_mask(m, shrink=False)
1657 array([False, False, False, False])
1658
1659 Using a flexible `dtype`.
1660
1661 >>> m = [1, 0, 1, 1]
1662 >>> n = [0, 1, 0, 0]
1663 >>> arr = []
1664 >>> for man, mouse in zip(m, n):

Callers 15

test_testCopySizeMethod · 0.90
test_testPutMethod · 0.90
test_copyMethod · 0.90
test_hardmaskMethod · 0.90
test_hardmask_againMethod · 0.90
test_putMethod · 0.90
test_put_hardmaskMethod · 0.90
test_make_maskMethod · 0.90
reduceMethod · 0.85
mask_orFunction · 0.85
masked_whereFunction · 0.85
masked_objectFunction · 0.85

Calls 3

make_mask_descrFunction · 0.85
filledFunction · 0.85
_shrink_maskFunction · 0.85

Tested by 8

test_testCopySizeMethod · 0.72
test_testPutMethod · 0.72
test_copyMethod · 0.72
test_hardmaskMethod · 0.72
test_hardmask_againMethod · 0.72
test_putMethod · 0.72
test_put_hardmaskMethod · 0.72
test_make_maskMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…