[Numpy-svn] r4748 - in branches/maskedarray/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed Jan 23 17:13:29 EST 2008
Author: stefan
Date: 2008-01-23 16:13:10 -0600 (Wed, 23 Jan 2008)
New Revision: 4748
Modified:
branches/maskedarray/numpy/ma/core.py
branches/maskedarray/numpy/ma/tests/test_core.py
Log:
Add 'compress'.
Modified: branches/maskedarray/numpy/ma/core.py
===================================================================
--- branches/maskedarray/numpy/ma/core.py 2008-01-23 12:27:26 UTC (rev 4747)
+++ branches/maskedarray/numpy/ma/core.py 2008-01-23 22:13:10 UTC (rev 4748)
@@ -26,8 +26,8 @@
'arctanh', 'argmax', 'argmin', 'argsort', 'around',
'array', 'asarray','asanyarray',
'bitwise_and', 'bitwise_or', 'bitwise_xor',
- 'ceil', 'choose', 'compressed', 'concatenate', 'conjugate',
- 'cos', 'cosh', 'count',
+ 'ceil', 'choose', 'compress', 'compressed', 'concatenate',
+ 'conjugate', 'cos', 'cosh', 'count',
'default_fill_value', 'diagonal', 'divide', 'dump', 'dumps',
'empty', 'empty_like', 'equal', 'exp',
'fabs', 'fmod', 'filled', 'floor', 'floor_divide','fix_invalid',
@@ -3099,6 +3099,12 @@
m = make_mask(mask_or(m, getmask(indices)), copy=0, shrink=True)
return masked_array(d, mask=m)
+def compress(a, condition):
+ """Return a where condition is True.
+
+ """
+ return a[condition]
+
def round_(a, decimals=0, out=None):
"""Return a copy of a, rounded to 'decimals' places.
Modified: branches/maskedarray/numpy/ma/tests/test_core.py
===================================================================
--- branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-23 12:27:26 UTC (rev 4747)
+++ branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-23 22:13:10 UTC (rev 4748)
@@ -1388,7 +1388,13 @@
putmask(mxx, mask, values)
assert_equal(mxx, [1,2,30,4,5,60])
+ def test_compress(self):
+ a = array([1,2,3],mask=[True,False,False])
+ b = compress(a,a<3)
+ assert_equal(b,[1,2])
+ assert_equal(b.mask,[True,False])
+
#..............................................................................
###############################################################################
More information about the Numpy-svn
mailing list