当前位置: 首页>>代码示例>>Python>>正文


Python testutils.assert_array_almost_equal方法代码示例

本文整理汇总了Python中numpy.ma.testutils.assert_array_almost_equal方法的典型用法代码示例。如果您正苦于以下问题:Python testutils.assert_array_almost_equal方法的具体用法?Python testutils.assert_array_almost_equal怎么用?Python testutils.assert_array_almost_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.ma.testutils的用法示例。


在下文中一共展示了testutils.assert_array_almost_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_simple(self):
        # Tests that each of the tests works as expected with default params
        #
        # basic tests, with expected results (no weighting)
        # results taken from the previous (slower) version of histogram
        basic_tests = ((self.low_values, (np.array([1., 1., 1., 2., 2.,
                                                     1., 1., 0., 1., 1.]),
                                          0.14444444444444446, 0.11111111111111112, 0)),
                       (self.high_range, (np.array([5., 0., 1., 1., 0.,
                                                     0., 5., 1., 0., 1.]),
                                          -3.1666666666666661, 10.333333333333332, 0)),
                       (self.low_range, (np.array([3., 1., 1., 1., 0., 1.,
                                                    1., 2., 3., 1.]),
                                         1.9388888888888889, 0.12222222222222223, 0)),
                       (self.few_values, (np.array([1., 0., 1., 0., 0., 0.,
                                                     0., 1., 0., 1.]),
                                          -1.2222222222222223, 0.44444444444444448, 0)),
                       )
        for inputs, expected_results in basic_tests:
            given_results = stats.histogram(inputs)
            assert_array_almost_equal(expected_results[0], given_results[0],
                                      decimal=2)
            for i in range(1, 4):
                assert_almost_equal(expected_results[i], given_results[i],
                                    decimal=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:test_stats.py

示例2: test_reduced_bins

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_reduced_bins(self):
        # Tests that reducing the number of bins produces expected results

        # basic tests, with expected results (no weighting),
        # except number of bins is halved to 5
        # results taken from the previous (slower) version of histogram
        basic_tests = ((self.low_values, (np.array([2., 3., 3., 1., 2.]),
                                          0.075000000000000011, 0.25, 0)),
                       (self.high_range, (np.array([5., 2., 0., 6., 1.]),
                                          -9.625, 23.25, 0)),
                       (self.low_range, (np.array([4., 2., 1., 3., 4.]),
                                         1.8625, 0.27500000000000002, 0)),
                       (self.few_values, (np.array([1., 1., 0., 1., 1.]),
                                          -1.5, 1.0, 0)),
                       )
        for inputs, expected_results in basic_tests:
            given_results = stats.histogram(inputs, numbins=5)
            assert_array_almost_equal(expected_results[0], given_results[0],
                                      decimal=2)
            for i in range(1, 4):
                assert_almost_equal(expected_results[i], given_results[i],
                                    decimal=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_stats.py

示例3: test_zmap_axis

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_zmap_axis(self):
        # Test use of 'axis' keyword in zmap.
        x = np.array([[0.0, 0.0, 1.0, 1.0],
                      [1.0, 1.0, 1.0, 2.0],
                      [2.0, 0.0, 2.0, 0.0]])

        t1 = 1.0/np.sqrt(2.0/3)
        t2 = np.sqrt(3.)/3
        t3 = np.sqrt(2.)

        z0 = stats.zmap(x, x, axis=0)
        z1 = stats.zmap(x, x, axis=1)

        z0_expected = [[-t1, -t3/2, -t3/2, 0.0],
                       [0.0, t3, -t3/2, t1],
                       [t1, -t3/2, t3, -t1]]
        z1_expected = [[-1.0, -1.0, 1.0, 1.0],
                       [-t2, -t2, -t2, np.sqrt(3.)],
                       [1.0, -1.0, 1.0, -1.0]]

        assert_array_almost_equal(z0, z0_expected)
        assert_array_almost_equal(z1, z1_expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_stats.py

示例4: test_zscore_axis

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_zscore_axis(self):
        # Test use of 'axis' keyword in zscore.
        x = np.array([[0.0, 0.0, 1.0, 1.0],
                      [1.0, 1.0, 1.0, 2.0],
                      [2.0, 0.0, 2.0, 0.0]])

        t1 = 1.0/np.sqrt(2.0/3)
        t2 = np.sqrt(3.)/3
        t3 = np.sqrt(2.)

        z0 = stats.zscore(x, axis=0)
        z1 = stats.zscore(x, axis=1)

        z0_expected = [[-t1, -t3/2, -t3/2, 0.0],
                       [0.0, t3, -t3/2, t1],
                       [t1, -t3/2, t3, -t1]]
        z1_expected = [[-1.0, -1.0, 1.0, 1.0],
                       [-t2, -t2, -t2, np.sqrt(3.)],
                       [1.0, -1.0, 1.0, -1.0]]

        assert_array_almost_equal(z0, z0_expected)
        assert_array_almost_equal(z1, z1_expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_stats.py

示例5: test_describe

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_describe():
    x = np.vstack((np.ones((3,4)),2*np.ones((2,4))))
    nc, mmc = (5, ([1., 1., 1., 1.], [2., 2., 2., 2.]))
    mc = np.array([1.4, 1.4, 1.4, 1.4])
    vc = np.array([0.3, 0.3, 0.3, 0.3])
    skc = [0.40824829046386357]*4
    kurtc = [-1.833333333333333]*4
    n, mm, m, v, sk, kurt = stats.describe(x)
    assert_equal(n, nc)
    assert_equal(mm, mmc)
    assert_equal(m, mc)
    assert_equal(v, vc)
    assert_array_almost_equal(sk, skc, decimal=13)  # not sure about precision
    assert_array_almost_equal(kurt, kurtc, decimal=13)
    n, mm, m, v, sk, kurt = stats.describe(x.T, axis=1)
    assert_equal(n, nc)
    assert_equal(mm, mmc)
    assert_equal(m, mc)
    assert_equal(v, vc)
    assert_array_almost_equal(sk, skc, decimal=13)  # not sure about precision
    assert_array_almost_equal(kurt, kurtc, decimal=13) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_stats.py

示例6: test_triinterpcubic_geom_weights

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_triinterpcubic_geom_weights():
    # Tests to check computation of weights for _DOF_estimator_geom:
    # The weight sum per triangle can be 1. (in case all angles < 90 degrees)
    # or (2*w_i) where w_i = 1-alpha_i/np.pi is the weight of apex i ; alpha_i
    # is the apex angle > 90 degrees.
    (ax, ay) = (0., 1.687)
    x = np.array([ax, 0.5*ax, 0., 1.])
    y = np.array([ay, -ay, 0., 0.])
    z = np.zeros(4, dtype=np.float64)
    triangles = [[0, 2, 3], [1, 3, 2]]
    sum_w = np.zeros([4, 2])  # 4 possibilities ; 2 triangles
    for theta in np.linspace(0., 2*np.pi, 14):  # rotating the figure...
        x_rot = np.cos(theta)*x + np.sin(theta)*y
        y_rot = -np.sin(theta)*x + np.cos(theta)*y
        triang = mtri.Triangulation(x_rot, y_rot, triangles)
        cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
        dof_estimator = mtri.triinterpolate._DOF_estimator_geom(cubic_geom)
        weights = dof_estimator.compute_geom_weights()
        # Testing for the 4 possibilities...
        sum_w[0, :] = np.sum(weights, 1) - 1
        for itri in range(3):
            sum_w[itri+1, :] = np.sum(weights, 1) - 2*weights[:, itri]
        assert_array_almost_equal(np.min(np.abs(sum_w), axis=0),
                                  np.array([0., 0.], dtype=np.float64)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:26,代码来源:test_triangulation.py

示例7: test_describe_axis_none

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_describe_axis_none(self):
        x = np.vstack((np.ones((3, 4)), 2 * np.ones((2, 4))))

        # expected values
        e_nobs, e_minmax = (20, (1.0, 2.0))
        e_mean = 1.3999999999999999
        e_var = 0.25263157894736848
        e_skew = 0.4082482904638634
        e_kurt = -1.8333333333333333

        # actual values
        a = stats.describe(x, axis=None)

        assert_equal(a.nobs, e_nobs)
        assert_almost_equal(a.minmax, e_minmax)
        assert_almost_equal(a.mean, e_mean)
        assert_almost_equal(a.variance, e_var)
        assert_array_almost_equal(a.skewness, e_skew, decimal=13)
        assert_array_almost_equal(a.kurtosis, e_kurt, decimal=13) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:21,代码来源:test_stats.py

示例8: test_triinterpcubic_geom_weights

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_triinterpcubic_geom_weights():
    # Tests to check computation of weights for _DOF_estimator_geom:
    # The weight sum per triangle can be 1. (in case all angles < 90 degrees)
    # or (2*w_i) where w_i = 1-alpha_i/np.pi is the weight of apex i; alpha_i
    # is the apex angle > 90 degrees.
    (ax, ay) = (0., 1.687)
    x = np.array([ax, 0.5*ax, 0., 1.])
    y = np.array([ay, -ay, 0., 0.])
    z = np.zeros(4, dtype=np.float64)
    triangles = [[0, 2, 3], [1, 3, 2]]
    sum_w = np.zeros([4, 2])  # 4 possibilities; 2 triangles
    for theta in np.linspace(0., 2*np.pi, 14):  # rotating the figure...
        x_rot = np.cos(theta)*x + np.sin(theta)*y
        y_rot = -np.sin(theta)*x + np.cos(theta)*y
        triang = mtri.Triangulation(x_rot, y_rot, triangles)
        cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
        dof_estimator = mtri.triinterpolate._DOF_estimator_geom(cubic_geom)
        weights = dof_estimator.compute_geom_weights()
        # Testing for the 4 possibilities...
        sum_w[0, :] = np.sum(weights, 1) - 1
        for itri in range(3):
            sum_w[itri+1, :] = np.sum(weights, 1) - 2*weights[:, itri]
        assert_array_almost_equal(np.min(np.abs(sum_w), axis=0),
                                  np.array([0., 0.], dtype=np.float64)) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:26,代码来源:test_triangulation.py

示例9: test_linregress

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_linregress(self):
        # compared with multivariate ols with pinv
        x = np.arange(11)
        y = np.arange(5,16)
        y[[(1),(-2)]] -= 1
        y[[(0),(-1)]] += 1

        res = (1.0, 5.0, 0.98229948625750, 7.45259691e-008, 0.063564172616372733)
        assert_array_almost_equal(stats.linregress(x,y),res,decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_stats.py

示例10: test_weighting

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_weighting(self):
        # Tests that weights give expected histograms

        # basic tests, with expected results, given a set of weights
        # weights used (first n are used for each test, where n is len of array) (14 values)
        weights = np.array([1., 3., 4.5, 0.1, -1.0, 0.0, 0.3, 7.0, 103.2, 2, 40, 0, 0, 1])
        # results taken from the numpy version of histogram
        basic_tests = ((self.low_values, (np.array([4.0, 0.0, 4.5, -0.9, 0.0,
                                                      0.3,110.2, 0.0, 0.0, 42.0]),
                                          0.2, 0.1, 0)),
                       (self.high_range, (np.array([9.6, 0., -1., 0., 0.,
                                                      0.,145.2, 0., 0.3, 7.]),
                                          2.0, 9.3, 0)),
                       (self.low_range, (np.array([2.4, 0., 0., 0., 0.,
                                                    2., 40., 0., 103.2, 13.5]),
                                         2.0, 0.11, 0)),
                       (self.few_values, (np.array([4.5, 0., 0.1, 0., 0., 0.,
                                                     0., 1., 0., 3.]),
                                          -1., 0.4, 0)),

                       )
        for inputs, expected_results in basic_tests:
            # use the first lot of weights for test
            # default limits given to reproduce output of numpy's test better
            given_results = stats.histogram(inputs, defaultlimits=(inputs.min(),
                                                                   inputs.max()),
                                            weights=weights[:len(inputs)])
            assert_array_almost_equal(expected_results[0], given_results[0],
                                      decimal=2)
            for i in range(1, 4):
                assert_almost_equal(expected_results[i], given_results[i],
                                    decimal=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:test_stats.py

示例11: test_increased_bins

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_increased_bins(self):
        # Tests that increasing the number of bins produces expected results

        # basic tests, with expected results (no weighting),
        # except number of bins is double to 20
        # results taken from the previous (slower) version of histogram
        basic_tests = ((self.low_values, (np.array([1., 0., 1., 0., 1.,
                                                     0., 2., 0., 1., 0.,
                                                     1., 1., 0., 1., 0.,
                                                     0., 0., 1., 0., 1.]),
                                          0.1736842105263158, 0.052631578947368418, 0)),
                       (self.high_range, (np.array([5., 0., 0., 0., 1.,
                                                     0., 1., 0., 0., 0.,
                                                     0., 0., 0., 5., 0.,
                                                     0., 1., 0., 0., 1.]),
                                          -0.44736842105263142, 4.8947368421052628, 0)),
                       (self.low_range, (np.array([3., 0., 1., 1., 0., 0.,
                                                    0., 1., 0., 0., 1., 0.,
                                                    1., 0., 1., 0., 1., 3.,
                                                    0., 1.]),
                                         1.9710526315789474, 0.057894736842105263, 0)),
                       (self.few_values, (np.array([1., 0., 0., 0., 0., 1.,
                                                     0., 0., 0., 0., 0., 0.,
                                                     0., 0., 1., 0., 0., 0.,
                                                     0., 1.]),
                                          -1.1052631578947367, 0.21052631578947367, 0)),
                       )
        for inputs, expected_results in basic_tests:
            given_results = stats.histogram(inputs, numbins=20)
            assert_array_almost_equal(expected_results[0], given_results[0],
                                      decimal=2)
            for i in range(1, 4):
                assert_almost_equal(expected_results[i], given_results[i],
                                    decimal=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:test_stats.py

示例12: test_relfreq

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_relfreq():
    a = np.array([1, 4, 2, 1, 3, 1])
    relfreqs, lowlim, binsize, extrapoints = stats.relfreq(a, numbins=4)
    assert_array_almost_equal(relfreqs, array([0.5, 0.16666667, 0.16666667, 0.16666667]))

    # check array_like input is accepted
    relfreqs2, lowlim, binsize, extrapoints = stats.relfreq([1, 4, 2, 1, 3, 1], numbins=4)
    assert_array_almost_equal(relfreqs, relfreqs2)


# Utility 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_stats.py

示例13: test_2D_array_default

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_2D_array_default(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))
        actual = stats.gmean(a)
        desired = array((1,2,3,4))
        assert_array_almost_equal(actual, desired, decimal=14)

        desired1 = stats.gmean(a,axis=0)
        assert_array_almost_equal(actual, desired1, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_stats.py

示例14: test_2D_array_dim1

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_2D_array_dim1(self):
        a = array(((1,2,3,4),
                   (1,2,3,4),
                   (1,2,3,4)))
        actual = stats.gmean(a, axis=1)
        v = power(1*2*3*4,1./4.)
        desired = array((v,v,v))
        assert_array_almost_equal(actual, desired, decimal=14) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_stats.py

示例15: test_zmap_ddof

# 需要导入模块: from numpy.ma import testutils [as 别名]
# 或者: from numpy.ma.testutils import assert_array_almost_equal [as 别名]
def test_zmap_ddof(self):
        # Test use of 'ddof' keyword in zmap.
        x = np.array([[0.0, 0.0, 1.0, 1.0],
                      [0.0, 1.0, 2.0, 3.0]])

        z = stats.zmap(x, x, axis=1, ddof=1)

        z0_expected = np.array([-0.5, -0.5, 0.5, 0.5])/(1.0/np.sqrt(3))
        z1_expected = np.array([-1.5, -0.5, 0.5, 1.5])/(np.sqrt(5./3))
        assert_array_almost_equal(z[0], z0_expected)
        assert_array_almost_equal(z[1], z1_expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_stats.py


注:本文中的numpy.ma.testutils.assert_array_almost_equal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。