summaryrefslogtreecommitdiff
path: root/numpy/ma/tests/test_extras.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2008-03-22 20:03:03 +0000
committerpierregm <pierregm@localhost>2008-03-22 20:03:03 +0000
commit5cb370e9234582f62231384c26a426301dad3331 (patch)
tree8d95cfba8219304ec211fb53f0d829468d458624 /numpy/ma/tests/test_extras.py
parenta70012ade70ba9912061ad2bac3e2a8196c72823 (diff)
downloadnumpy-5cb370e9234582f62231384c26a426301dad3331.tar.gz
core : fixed sort when axis is None
mstats : fixed mmedian, renamed to median and moved to numpy.ma.extras for compatibility extras : introduced median from mstats mrecords: * fixed __array_finalize__ to keep the mask of a masked array when viewing it as a mrecarray * simplified _getdata
Diffstat (limited to 'numpy/ma/tests/test_extras.py')
-rw-r--r--numpy/ma/tests/test_extras.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 5a52aeeee..2e1eebb04 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -324,6 +324,36 @@ class TestApplyAlongAxis(NumpyTestCase):
return b[1]
xa = apply_along_axis(myfunc,2,a)
assert_equal(xa,[[1,4],[7,10]])
+
+class TestMedian(NumpyTestCase):
+ def __init__(self, *args, **kwds):
+ NumpyTestCase.__init__(self, *args, **kwds)
+ #
+ def test_2d(self):
+ "Tests median w/ 2D"
+ (n,p) = (101,30)
+ x = masked_array(numpy.linspace(-1.,1.,n),)
+ x[:10] = x[-10:] = masked
+ z = masked_array(numpy.empty((n,p), dtype=numpy.float_))
+ z[:,0] = x[:]
+ idx = numpy.arange(len(x))
+ for i in range(1,p):
+ numpy.random.shuffle(idx)
+ z[:,i] = x[idx]
+ assert_equal(median(z[:,0]), 0)
+ assert_equal(median(z), numpy.zeros((p,)))
+ #
+ def test_3d(self):
+ "Tests median w/ 3D"
+ x = numpy.ma.arange(24).reshape(3,4,2)
+ x[x%3==0] = masked
+ assert_equal(median(x,0), [[12,9],[6,15],[12,9],[18,15]])
+ x.shape = (4,3,2)
+ assert_equal(median(x,0),[[99,10],[11,99],[13,14]])
+ x = numpy.ma.arange(24).reshape(4,3,2)
+ x[x%5==0] = masked
+ assert_equal(median(x,0), [[12,10],[8,9],[16,17]])
+
###############################################################################
#------------------------------------------------------------------------------