Example #1
0
    def test_2D(self):
        a = ma.array(((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4)),
                     mask=((0, 0, 0, 0), (1, 0, 0, 1), (0, 1, 1, 0)))
        actual = mstats.gmean(a)
        desired = np.array((1, 2, 3, 4))
        assert_array_almost_equal(actual, desired, decimal=14)

        desired1 = mstats.gmean(a, axis=0)
        assert_array_almost_equal(actual, desired1, decimal=14)

        actual = mstats.gmean(a, -1)
        desired = ma.array(
            (np.power(1 * 2 * 3 * 4,
                      1. / 4.), np.power(2 * 3,
                                         1. / 2.), np.power(1 * 4, 1. / 2.)))
        assert_array_almost_equal(actual, desired, decimal=14)
Example #2
0
    def test_1D(self):
        a = (1, 2, 3, 4)
        actual = mstats.gmean(a)
        desired = np.power(1 * 2 * 3 * 4, 1. / 4.)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = mstats.gmean(a, axis=-1)
        assert_almost_equal(actual, desired1, decimal=14)
        assert_(not isinstance(desired1, ma.MaskedArray))

        a = ma.array((1, 2, 3, 4), mask=(0, 0, 0, 1))
        actual = mstats.gmean(a)
        desired = np.power(1 * 2 * 3, 1. / 3.)
        assert_almost_equal(actual, desired, decimal=14)

        desired1 = mstats.gmean(a, axis=-1)
        assert_almost_equal(actual, desired1, decimal=14)
Example #3
0
 def test_1D_float96(self):
     a = ma.array((1, 2, 3, 4), mask=(0, 0, 0, 1))
     actual_dt = mstats.gmean(a, dtype=np.float96)
     desired_dt = np.power(1 * 2 * 3, 1. / 3.).astype(np.float96)
     assert_almost_equal(actual_dt, desired_dt, decimal=14)
     assert_(actual_dt.dtype == desired_dt.dtype)