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

Function mask_or

numpy/ma/core.py:1704–1757  ·  view source on GitHub ↗

Combine two masks with the ``logical_or`` operator. The result may be a view on `m1` or `m2` if the other is `nomask` (i.e. False). Parameters ---------- m1, m2 : array_like Input masks. copy : bool, optional If copy is False and one of the inputs is `n

(m1, m2, copy=False, shrink=True)

Source from the content-addressed store, hash-verified

1702
1703
1704def mask_or(m1, m2, copy=False, shrink=True):
1705 """
1706 Combine two masks with the ``logical_or`` operator.
1707
1708 The result may be a view on `m1` or `m2` if the other is `nomask`
1709 (i.e. False).
1710
1711 Parameters
1712 ----------
1713 m1, m2 : array_like
1714 Input masks.
1715 copy : bool, optional
1716 If copy is False and one of the inputs is `nomask`, return a view
1717 of the other input mask. Defaults to False.
1718 shrink : bool, optional
1719 Whether to shrink the output to `nomask` if all its values are
1720 False. Defaults to True.
1721
1722 Returns
1723 -------
1724 mask : output mask
1725 The result masks values that are masked in either `m1` or `m2`.
1726
1727 Raises
1728 ------
1729 ValueError
1730 If `m1` and `m2` have different flexible dtypes.
1731
1732 Examples
1733 --------
1734 >>> m1 = np.ma.make_mask([0, 1, 1, 0])
1735 >>> m2 = np.ma.make_mask([1, 0, 0, 0])
1736 >>> np.ma.mask_or(m1, m2)
1737 array([ True, True, True, False])
1738
1739 """
1740
1741 if (m1 is nomask) or (m1 is False):
1742 dtype = getattr(m2, 'dtype', MaskType)
1743 return make_mask(m2, copy=copy, shrink=shrink, dtype=dtype)
1744 if (m2 is nomask) or (m2 is False):
1745 dtype = getattr(m1, 'dtype', MaskType)
1746 return make_mask(m1, copy=copy, shrink=shrink, dtype=dtype)
1747 if m1 is m2 and is_mask(m1):
1748 return m1
1749 (dtype1, dtype2) = (getattr(m1, 'dtype', None), getattr(m2, 'dtype', None))
1750 if dtype1 != dtype2:
1751 raise ValueError("Incompatible dtypes '%s'<>'%s'" % (dtype1, dtype2))
1752 if dtype1.names is not None:
1753 # Allocate an output mask array with the properly broadcast shape.
1754 newmask = np.empty(np.broadcast(m1, m2).shape, dtype1)
1755 _recursive_mask_or(m1, m2, newmask)
1756 return newmask
1757 return make_mask(umath.logical_or(m1, m2), copy=copy, shrink=shrink)
1758
1759
1760def flatten_mask(mask):

Calls 3

make_maskFunction · 0.85
is_maskFunction · 0.85
_recursive_mask_orFunction · 0.85