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

Function mask_or

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

1757
1758
1759def mask_or(m1, m2, copy=False, shrink=True):
1760 """
1761 Combine two masks with the ``logical_or`` operator.
1762
1763 The result may be a view on `m1` or `m2` if the other is `nomask`
1764 (i.e. False).
1765
1766 Parameters
1767 ----------
1768 m1, m2 : array_like
1769 Input masks.
1770 copy : bool, optional
1771 If copy is False and one of the inputs is `nomask`, return a view
1772 of the other input mask. Defaults to False.
1773 shrink : bool, optional
1774 Whether to shrink the output to `nomask` if all its values are
1775 False. Defaults to True.
1776
1777 Returns
1778 -------
1779 mask : output mask
1780 The result masks values that are masked in either `m1` or `m2`.
1781
1782 Raises
1783 ------
1784 ValueError
1785 If `m1` and `m2` have different flexible dtypes.
1786
1787 Examples
1788 --------
1789 >>> import numpy as np
1790 >>> m1 = np.ma.make_mask([0, 1, 1, 0])
1791 >>> m2 = np.ma.make_mask([1, 0, 0, 0])
1792 >>> np.ma.mask_or(m1, m2)
1793 array([ True, True, True, False])
1794
1795 """
1796
1797 if (m1 is nomask) or (m1 is False):
1798 dtype = getattr(m2, 'dtype', MaskType)
1799 return make_mask(m2, copy=copy, shrink=shrink, dtype=dtype)
1800 if (m2 is nomask) or (m2 is False):
1801 dtype = getattr(m1, 'dtype', MaskType)
1802 return make_mask(m1, copy=copy, shrink=shrink, dtype=dtype)
1803 if m1 is m2 and is_mask(m1):
1804 return _shrink_mask(m1) if shrink else m1
1805 (dtype1, dtype2) = (getattr(m1, 'dtype', None), getattr(m2, 'dtype', None))
1806 if dtype1 != dtype2:
1807 raise ValueError(f"Incompatible dtypes '{dtype1}'<>'{dtype2}'")
1808 if dtype1.names is not None:
1809 # Allocate an output mask array with the properly broadcast shape.
1810 newmask = np.empty(np.broadcast(m1, m2).shape, dtype1)
1811 _recursive_mask_or(m1, m2, newmask)
1812 return newmask
1813 return make_mask(umath.logical_or(m1, m2), copy=copy, shrink=shrink)
1814
1815
1816def flatten_mask(mask):

Calls 4

make_maskFunction · 0.85
is_maskFunction · 0.85
_shrink_maskFunction · 0.85
_recursive_mask_orFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…