[Numpy-svn] r5251 - in trunk/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Tue Jun 3 19:14:19 EDT 2008
Author: pierregm
Date: 2008-06-03 18:14:16 -0500 (Tue, 03 Jun 2008)
New Revision: 5251
Modified:
trunk/numpy/ma/core.py
trunk/numpy/ma/tests/test_core.py
Log:
core
* masked_values now accept a shrink argument
* fixed the divide_tolerance to numpy.finfo(float).tiny (bug #807)
* in MaskedArray.__idiv__, use np.where instead of np.putmask to mask the denominator
Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py 2008-06-03 22:36:09 UTC (rev 5250)
+++ trunk/numpy/ma/core.py 2008-06-03 23:14:16 UTC (rev 5251)
@@ -76,7 +76,7 @@
MaskType = np.bool_
nomask = MaskType(0)
-divide_tolerance = 1.e-35
+divide_tolerance = np.finfo(float).tiny
np.seterr(all='ignore')
def doc_note(note):
@@ -926,15 +926,22 @@
return masked_where(condition, x, copy=copy)
#
-def masked_object(x, value, copy=True):
+def masked_object(x, value, copy=True, shrink=True):
"""Mask the array x where the data are exactly equal to value.
This function is suitable only for object arrays: for floating
point, please use ``masked_values`` instead.
- Notes
- -----
- The mask is set to `nomask` if posible.
+ Parameters
+ ----------
+ x : array-like
+ Array to mask
+ value : var
+ Comparison value
+ copy : {True, False}, optional
+ Whether to return a copy of x.
+ shrink : {True, False}, optional
+ Whether to collapse a mask full of False to nomask
"""
if isMaskedArray(x):
@@ -943,10 +950,10 @@
else:
condition = umath.equal(np.asarray(x), value)
mask = nomask
- mask = mask_or(mask, make_mask(condition, shrink=True))
+ mask = mask_or(mask, make_mask(condition, shrink=shrink))
return masked_array(x, mask=mask, copy=copy, fill_value=value)
-def masked_values(x, value, rtol=1.e-5, atol=1.e-8, copy=True):
+def masked_values(x, value, rtol=1.e-5, atol=1.e-8, copy=True, shrink=True):
"""Mask the array x where the data are approximately equal in
value, i.e.
@@ -961,12 +968,14 @@
Array to fill.
value : float
Masking value.
- rtol : float
+ rtol : {float}, optional
Tolerance parameter.
- atol : float
+ atol : {float}, optional
Tolerance parameter (1e-8).
- copy : bool
+ copy : {True, False}, optional
Whether to return a copy of x.
+ shrink : {True, False}, optional
+ Whether to collapse a mask full of False to nomask
"""
abs = umath.absolute
@@ -977,7 +986,7 @@
else:
condition = umath.equal(xnew, value)
mask = nomask
- mask = mask_or(mask, make_mask(condition, shrink=True))
+ mask = mask_or(mask, make_mask(condition, shrink=shrink))
return masked_array(xnew, mask=mask, copy=copy, fill_value=value)
def masked_invalid(a, copy=True):
@@ -1776,8 +1785,8 @@
new_mask = mask_or(other_mask, dom_mask)
# The following 3 lines control the domain filling
if dom_mask.any():
- other_data = other_data.copy()
- np.putmask(other_data, dom_mask, 1)
+ (_, fval) = ufunc_fills[np.divide]
+ other_data = np.where(dom_mask, fval, other_data)
ndarray.__idiv__(self._data, other_data)
self._mask = mask_or(self._mask, new_mask)
return self
Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py 2008-06-03 22:36:09 UTC (rev 5250)
+++ trunk/numpy/ma/tests/test_core.py 2008-06-03 23:14:16 UTC (rev 5251)
@@ -242,6 +242,11 @@
assert_equal(xm._mask, [1,1,1,0,0,1,1,0,0,0,1,1])
assert_equal(xm._data, [1/5.,1.,1./3.,-1.,-pi/2.,-1.,5.,1.,1.,1.,2.,1.])
+ def test_inplace_arithmetixx(self):
+ tiny = numpy.finfo(float).tiny
+ a = array([tiny, 1./tiny, 0.])
+ assert_equal(getmaskarray(a/2), [0,0,0])
+ assert_equal(getmaskarray(2/a), [1,0,1])
#..........................
def test_scalararithmetic(self):
More information about the Numpy-svn
mailing list