MCPcopy Create free account
hub / github.com/numpy/numpy / make_mask

Function make_mask

numpy/ma/core.py:1555–1641  ·  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

1553
1554
1555def make_mask(m, copy=False, shrink=True, dtype=MaskType):
1556 """
1557 Create a boolean mask from an array.
1558
1559 Return `m` as a boolean mask, creating a copy if necessary or requested.
1560 The function can accept any sequence that is convertible to integers,
1561 or ``nomask``. Does not require that contents must be 0s and 1s, values
1562 of 0 are interpreted as False, everything else as True.
1563
1564 Parameters
1565 ----------
1566 m : array_like
1567 Potential mask.
1568 copy : bool, optional
1569 Whether to return a copy of `m` (True) or `m` itself (False).
1570 shrink : bool, optional
1571 Whether to shrink `m` to ``nomask`` if all its values are False.
1572 dtype : dtype, optional
1573 Data-type of the output mask. By default, the output mask has a
1574 dtype of MaskType (bool). If the dtype is flexible, each field has
1575 a boolean dtype. This is ignored when `m` is ``nomask``, in which
1576 case ``nomask`` is always returned.
1577
1578 Returns
1579 -------
1580 result : ndarray
1581 A boolean mask derived from `m`.
1582
1583 Examples
1584 --------
1585 >>> import numpy.ma as ma
1586 >>> m = [True, False, True, True]
1587 >>> ma.make_mask(m)
1588 array([ True, False, True, True])
1589 >>> m = [1, 0, 1, 1]
1590 >>> ma.make_mask(m)
1591 array([ True, False, True, True])
1592 >>> m = [1, 0, 2, -3]
1593 >>> ma.make_mask(m)
1594 array([ True, False, True, True])
1595
1596 Effect of the `shrink` parameter.
1597
1598 >>> m = np.zeros(4)
1599 >>> m
1600 array([0., 0., 0., 0.])
1601 >>> ma.make_mask(m)
1602 False
1603 >>> ma.make_mask(m, shrink=False)
1604 array([False, False, False, False])
1605
1606 Using a flexible `dtype`.
1607
1608 >>> m = [1, 0, 1, 1]
1609 >>> n = [0, 1, 0, 0]
1610 >>> arr = []
1611 >>> for man, mouse in zip(m, n):
1612 ... arr.append((man, mouse))

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