diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:50:49 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:50:49 +0000 |
commit | 4b4d5e6169fda3fad6e6587be43aefd30089e164 (patch) | |
tree | e7b923820d9f045d40a32d5868bd6876a30541b3 /numpy | |
parent | a8bcb84ba972a11fe49f28945abc986192ae73dc (diff) | |
download | numpy-4b4d5e6169fda3fad6e6587be43aefd30089e164.tar.gz |
3K: ENH: ma: implement data-preserving __ifloordiv__ and __itruediv__
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 402916501..aaa257807 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -3726,6 +3726,36 @@ class MaskedArray(ndarray): self._mask |= new_mask ndarray.__idiv__(self._data, np.where(self._mask, 1, other_data)) return self + #.... + def __ifloordiv__(self, other): + "Floor divide self by other in-place." + other_data = getdata(other) + dom_mask = _DomainSafeDivide().__call__(self._data, other_data) + other_mask = getmask(other) + new_mask = mask_or(other_mask, dom_mask) + # The following 3 lines control the domain filling + if dom_mask.any(): + (_, fval) = ufunc_fills[np.floor_divide] + other_data = np.where(dom_mask, fval, other_data) +# self._mask = mask_or(self._mask, new_mask) + self._mask |= new_mask + ndarray.__ifloordiv__(self._data, np.where(self._mask, 1, other_data)) + return self + #.... + def __itruediv__(self, other): + "True divide self by other in-place." + other_data = getdata(other) + dom_mask = _DomainSafeDivide().__call__(self._data, other_data) + other_mask = getmask(other) + new_mask = mask_or(other_mask, dom_mask) + # The following 3 lines control the domain filling + if dom_mask.any(): + (_, fval) = ufunc_fills[np.true_divide] + other_data = np.where(dom_mask, fval, other_data) +# self._mask = mask_or(self._mask, new_mask) + self._mask |= new_mask + ndarray.__itruediv__(self._data, np.where(self._mask, 1, other_data)) + return self #... def __ipow__(self, other): "Raise self to the power other, in place." |