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.hmean(a) desired = ma.array((1, 2, 3, 4)) assert_array_almost_equal(actual, desired, decimal=14) actual1 = mstats.hmean(a, axis=-1) desired = (4. / (1 / 1. + 1 / 2. + 1 / 3. + 1 / 4.), 2. / (1 / 2. + 1 / 3.), 2. / (1 / 1. + 1 / 4.)) assert_array_almost_equal(actual1, desired, decimal=14)
def test_1D(self): a = (1, 2, 3, 4) actual = mstats.hmean(a) desired = 4. / (1. / 1 + 1. / 2 + 1. / 3 + 1. / 4) assert_almost_equal(actual, desired, decimal=14) desired1 = mstats.hmean(ma.array(a), axis=-1) assert_almost_equal(actual, desired1, decimal=14) a = ma.array((1, 2, 3, 4), mask=(0, 0, 0, 1)) actual = mstats.hmean(a) desired = 3. / (1. / 1 + 1. / 2 + 1. / 3) assert_almost_equal(actual, desired, decimal=14) desired1 = mstats.hmean(a, axis=-1) assert_almost_equal(actual, desired1, decimal=14)
def test_1D_float96(self): a = ma.array((1, 2, 3, 4), mask=(0, 0, 0, 1)) actual_dt = mstats.hmean(a, dtype=np.float96) desired_dt = np.asarray(3. / (1. / 1 + 1. / 2 + 1. / 3), dtype=np.float96) assert_almost_equal(actual_dt, desired_dt, decimal=14) assert_(actual_dt.dtype == desired_dt.dtype)