コード例 #1
0
ファイル: test_mstats_basic.py プロジェクト: alouisos/scipy
    def test_trim(self):
        a = ma.arange(10)
        assert_equal(mstats.trim(a), [0,1,2,3,4,5,6,7,8,9])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,(2,8)), [None,None,2,3,4,5,6,7,8,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(2,8),inclusive=(False,False)),
                     [None,None,None,3,4,5,6,7,None,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(0.1,0.2),relative=True),
                     [None,1,2,3,4,5,6,7,None,None])

        a = ma.arange(12)
        a[[0,-1]] = a[5] = masked
        assert_equal(mstats.trim(a,(2,8)),
                     [None,None,2,3,4,None,6,7,8,None,None,None])

        x = ma.arange(100).reshape(10,10)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
        assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
        assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=-1)
        assert_equal(trimx._mask.T.ravel(),[1]*10+[0]*70+[1]*20)

        x = ma.arange(110).reshape(11,10)
        x[1] = masked
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
        assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
        trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
        assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
        trimx = mstats.trim(x.T,(0.1,0.2),relative=True,axis=-1)
        assert_equal(trimx.T._mask.ravel(),[1]*20+[0]*70+[1]*20)
コード例 #2
0
ファイル: test_mstats_basic.py プロジェクト: andycasey/scipy
    def test_trim(self):
        a = ma.arange(10)
        assert_equal(mstats.trim(a), [0,1,2,3,4,5,6,7,8,9])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,(2,8)), [None,None,2,3,4,5,6,7,8,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(2,8),inclusive=(False,False)),
                     [None,None,None,3,4,5,6,7,None,None])
        a = ma.arange(10)
        assert_equal(mstats.trim(a,limits=(0.1,0.2),relative=True),
                     [None,1,2,3,4,5,6,7,None,None])

        a = ma.arange(12)
        a[[0,-1]] = a[5] = masked
        assert_equal(mstats.trim(a, (2,8)),
                     [None, None, 2, 3, 4, None, 6, 7, 8, None, None, None])

        x = ma.arange(100).reshape(10, 10)
        expected = [1]*10 + [0]*70 + [1]*20
        trimx = mstats.trim(x, (0.1,0.2), relative=True, axis=None)
        assert_equal(trimx._mask.ravel(), expected)
        trimx = mstats.trim(x, (0.1,0.2), relative=True, axis=0)
        assert_equal(trimx._mask.ravel(), expected)
        trimx = mstats.trim(x, (0.1,0.2), relative=True, axis=-1)
        assert_equal(trimx._mask.T.ravel(), expected)

        # same as above, but with an extra masked row inserted
        x = ma.arange(110).reshape(11, 10)
        x[1] = masked
        expected = [1]*20 + [0]*70 + [1]*20
        trimx = mstats.trim(x, (0.1,0.2), relative=True, axis=None)
        assert_equal(trimx._mask.ravel(), expected)
        trimx = mstats.trim(x, (0.1,0.2), relative=True, axis=0)
        assert_equal(trimx._mask.ravel(), expected)
        trimx = mstats.trim(x.T, (0.1,0.2), relative=True, axis=-1)
        assert_equal(trimx.T._mask.ravel(), expected)
コード例 #3
0
 def test_trim(self):
     "Tests trimming"
     a = ma.arange(10)
     assert_equal(mstats.trim(a), [0,1,2,3,4,5,6,7,8,9])
     a = ma.arange(10)
     assert_equal(mstats.trim(a,(2,8)), [None,None,2,3,4,5,6,7,8,None])
     a = ma.arange(10)
     assert_equal(mstats.trim(a,limits=(2,8),inclusive=(False,False)),
                  [None,None,None,3,4,5,6,7,None,None])
     a = ma.arange(10)
     assert_equal(mstats.trim(a,limits=(0.1,0.2),relative=True),
                  [None,1,2,3,4,5,6,7,None,None])
     #
     a = ma.arange(12)
     a[[0,-1]] = a[5] = masked
     assert_equal(mstats.trim(a,(2,8)),
                  [None,None,2,3,4,None,6,7,8,None,None,None])
     #
     x = ma.arange(100).reshape(10,10)
     trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
     assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
     trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
     assert_equal(trimx._mask.ravel(),[1]*10+[0]*70+[1]*20)
     trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=-1)
     assert_equal(trimx._mask.T.ravel(),[1]*10+[0]*70+[1]*20)
     #
     x = ma.arange(110).reshape(11,10)
     x[1] = masked
     trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=None)
     assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
     trimx = mstats.trim(x,(0.1,0.2),relative=True,axis=0)
     assert_equal(trimx._mask.ravel(),[1]*20+[0]*70+[1]*20)
     trimx = mstats.trim(x.T,(0.1,0.2),relative=True,axis=-1)
     assert_equal(trimx.T._mask.ravel(),[1]*20+[0]*70+[1]*20)