當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.assert_方法代碼示例

本文整理匯總了Python中numpy.testing.assert_方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.assert_方法的具體用法?Python testing.assert_怎麽用?Python testing.assert_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.testing的用法示例。


在下文中一共展示了testing.assert_方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_function

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == b'2')
            r = t('ab')
            assert_(r == b'a', repr(r))
            r = t(array('ab'))
            assert_(r == b'a', repr(r))
            r = t(array(77, 'u1'))
            assert_(r == b'M', repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == b'23        ', repr(t(23)))
            assert_(t('123456789abcdef') == b'123456789a')
        elif tname in ['t5', 's5']:
            assert_(t(23) == b'23   ', repr(t(23)))
            assert_(t('ab') == b'ab   ', repr(t('ab')))
            assert_(t('123456789abcdef') == b'12345')
        else:
            raise NotImplementedError 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_return_character.py

示例2: check_function

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:test_return_character.py

示例3: test_predict_freq

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_predict_freq():
    # test that predicted dates have same frequency
    x = np.arange(1,36.)

    # there's a bug in pandas up to 0.10.2 for YearBegin
    #dates = date_range("1972-4-1", "2007-4-1", freq="AS-APR")
    dates = pd.date_range("1972-4-30", "2006-4-30", freq="A-APR")
    series = pd.Series(x, index=dates)
    model = TimeSeriesModel(series)
    #npt.assert_(model.data.freq == "AS-APR")
    assert_equal(model._index.freqstr, "A-APR")

    start, end, out_of_sample, _ = (
        model._get_prediction_index("2006-4-30", "2016-4-30"))

    predict_dates = model.data.predict_dates

    #expected_dates = date_range("2006-12-31", "2016-12-31",
    #                            freq="AS-APR")
    expected_dates = pd.date_range("2006-4-30", "2016-4-30", freq="A-APR")
    assert_equal(predict_dates, expected_dates)
    #ptesting.assert_series_equal(predict_dates, expected_dates) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:test_base.py

示例4: test_recursive_split

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_recursive_split():
    keys = list(product('mf'))
    data = OrderedDict(zip(keys, [1] * len(keys)))
    res = _hierarchical_split(data, gap=0)
    assert_(list(iterkeys(res)) == keys)
    res[('m',)] = (0.0, 0.0, 0.5, 1.0)
    res[('f',)] = (0.5, 0.0, 0.5, 1.0)
    keys = list(product('mf', 'yao'))
    data = OrderedDict(zip(keys, [1] * len(keys)))
    res = _hierarchical_split(data, gap=0)
    assert_(list(iterkeys(res)) == keys)
    res[('m', 'y')] = (0.0, 0.0, 0.5, 1 / 3)
    res[('m', 'a')] = (0.0, 1 / 3, 0.5, 1 / 3)
    res[('m', 'o')] = (0.0, 2 / 3, 0.5, 1 / 3)
    res[('f', 'y')] = (0.5, 0.0, 0.5, 1 / 3)
    res[('f', 'a')] = (0.5, 1 / 3, 0.5, 1 / 3)
    res[('f', 'o')] = (0.5, 2 / 3, 0.5, 1 / 3) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:test_mosaicplot.py

示例5: check_sample_mean

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def check_sample_mean(sm,v,n, popmean):
    """
from stats.stats.ttest_1samp(a, popmean):
Calculates the t-obtained for the independent samples T-test on ONE group
of scores a, given a population mean.

Returns: t-value, two-tailed prob
"""
##    a = asarray(a)
##    x = np.mean(a)
##    v = np.var(a, ddof=1)
##    n = len(a)
    df = n-1
    svar = ((n-1)*v) / float(df)    # looks redundant
    t = (sm-popmean)/np.sqrt(svar*(1.0/n))
    prob = stats.betai(0.5*df,0.5,df/(df+t*t))

    # return t,prob
    npt.assert_(prob > 0.01, 'mean fail, t,prob = %f, %f, m,sm=%f,%f' % (t,prob,popmean,sm)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:21,代碼來源:test_continuous_basic.py

示例6: test_fit_csd

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_fit_csd():
    fdata, fbval, fbvec = dpd.get_fnames('small_64D')
    with nbtmp.InTemporaryDirectory() as tmpdir:
        # Convert from npy to txt:
        bvals = np.loadtxt(fbval)
        bvecs = np.loadtxt(fbvec)
        np.savetxt(op.join(tmpdir, 'bvals.txt'), bvals)
        np.savetxt(op.join(tmpdir, 'bvecs.txt'), bvecs)
        for sh_order in [4, 6]:
            fname = csd.fit_csd(fdata, op.join(tmpdir, 'bvals.txt'),
                                op.join(tmpdir, 'bvecs.txt'),
                                out_dir=tmpdir, sh_order=sh_order)
            npt.assert_(op.exists(fname))
            sh_coeffs_img = nib.load(fname)
            npt.assert_equal(sh_order,
                             calculate_max_order(sh_coeffs_img.shape[-1])) 
開發者ID:yeatmanlab,項目名稱:pyAFQ,代碼行數:18,代碼來源:test_csd.py

示例7: test_register_dwi

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_register_dwi():
    fdata, fbval, fbvec = dpd.get_fnames('small_64D')
    with nbtmp.InTemporaryDirectory() as tmpdir:
        # Use an abbreviated data-set:
        img = nib.load(fdata)
        data = img.get_fdata()[..., :10]
        nib.save(nib.Nifti1Image(data, img.affine),
                 op.join(tmpdir, 'data.nii.gz'))
        # Save a subset:
        bvals = np.loadtxt(fbval)
        bvecs = np.loadtxt(fbvec)
        np.savetxt(op.join(tmpdir, 'bvals.txt'), bvals[:10])
        np.savetxt(op.join(tmpdir, 'bvecs.txt'), bvecs[:10])
        reg_file = register_dwi(op.join(tmpdir, 'data.nii.gz'),
                                op.join(tmpdir, 'bvals.txt'),
                                op.join(tmpdir, 'bvecs.txt'))
        npt.assert_(op.exists(reg_file)) 
開發者ID:yeatmanlab,項目名稱:pyAFQ,代碼行數:19,代碼來源:test_registration.py

示例8: test_csd_tracking

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_csd_tracking():
    for sh_order in [4, 8, 10]:
        fname = fit_csd(fdata, fbval, fbvec,
                        response=((0.0015, 0.0003, 0.0003), 100),
                        sh_order=8, lambda_=1, tau=0.1, mask=None,
                        out_dir=tmpdir.name)
        for directions in ["det", "prob"]:
            sl = track(fname, directions,
                       odf_model="CSD",
                       max_angle=30.,
                       sphere=None,
                       seed_mask=None,
                       n_seeds=seeds,
                       stop_mask=None,
                       step_size=step_size,
                       min_length=min_length).streamlines

            npt.assert_(len(sl[0]) >= step_size * min_length) 
開發者ID:yeatmanlab,項目名稱:pyAFQ,代碼行數:20,代碼來源:test_tractography.py

示例9: assert_startswith

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def assert_startswith(a, b):
    # produces a better error message than assert_(a.startswith(b))
    assert_equal(a[:len(b)], b) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_subclassing.py

示例10: test_data_subclassing

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_data_subclassing(self):
        # Tests whether the subclass is kept.
        x = np.arange(5)
        m = [0, 0, 1, 0, 0]
        xsub = SubArray(x)
        xmsub = masked_array(xsub, mask=m)
        assert_(isinstance(xmsub, MaskedArray))
        assert_equal(xmsub._data, xsub)
        assert_(isinstance(xmsub._data, SubArray)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_subclassing.py

示例11: test_maskedarray_subclassing

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_maskedarray_subclassing(self):
        # Tests subclassing MaskedArray
        (x, mx) = self.data
        assert_(isinstance(mx._data, subarray)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_subclassing.py

示例12: test_masked_binary_operations

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_masked_binary_operations(self):
        # Tests masked_binary_operation
        (x, mx) = self.data
        # Result should be a msubarray
        assert_(isinstance(add(mx, mx), msubarray))
        assert_(isinstance(add(mx, x), msubarray))
        # Result should work
        assert_equal(add(mx, x), mx+x)
        assert_(isinstance(add(mx, mx)._data, subarray))
        assert_(isinstance(add.outer(mx, mx), msubarray))
        assert_(isinstance(hypot(mx, mx), msubarray))
        assert_(isinstance(hypot(mx, x), msubarray)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_subclassing.py

示例13: test_masked_binary_operations2

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_masked_binary_operations2(self):
        # Tests domained_masked_binary_operation
        (x, mx) = self.data
        xmx = masked_array(mx.data.__array__(), mask=mx.mask)
        assert_(isinstance(divide(mx, mx), msubarray))
        assert_(isinstance(divide(mx, x), msubarray))
        assert_equal(divide(mx, mx), divide(xmx, xmx)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_subclassing.py

示例14: test_attributepropagation

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_attributepropagation(self):
        x = array(arange(5), mask=[0]+[1]*4)
        my = masked_array(subarray(x))
        ym = msubarray(x)
        #
        z = (my+1)
        assert_(isinstance(z, MaskedArray))
        assert_(not isinstance(z, MSubArray))
        assert_(isinstance(z._data, SubArray))
        assert_equal(z._data.info, {})
        #
        z = (ym+1)
        assert_(isinstance(z, MaskedArray))
        assert_(isinstance(z, MSubArray))
        assert_(isinstance(z._data, SubArray))
        assert_(z._data.info['added'] > 0)
        # Test that inplace methods from data get used (gh-4617)
        ym += 1
        assert_(isinstance(ym, MaskedArray))
        assert_(isinstance(ym, MSubArray))
        assert_(isinstance(ym._data, SubArray))
        assert_(ym._data.info['iadded'] > 0)
        #
        ym._set_mask([1, 0, 0, 0, 1])
        assert_equal(ym._mask, [1, 0, 0, 0, 1])
        ym._series._set_mask([0, 0, 0, 0, 1])
        assert_equal(ym._mask, [0, 0, 0, 0, 1])
        #
        xsub = subarray(x, info={'name':'x'})
        mxsub = masked_array(xsub)
        assert_(hasattr(mxsub, 'info'))
        assert_equal(mxsub.info, xsub.info) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:34,代碼來源:test_subclassing.py

示例15: test_subclasspreservation

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_ [as 別名]
def test_subclasspreservation(self):
        # Checks that masked_array(...,subok=True) preserves the class.
        x = np.arange(5)
        m = [0, 0, 1, 0, 0]
        xinfo = [(i, j) for (i, j) in zip(x, m)]
        xsub = MSubArray(x, mask=m, info={'xsub':xinfo})
        #
        mxsub = masked_array(xsub, subok=False)
        assert_(not isinstance(mxsub, MSubArray))
        assert_(isinstance(mxsub, MaskedArray))
        assert_equal(mxsub._mask, m)
        #
        mxsub = asarray(xsub)
        assert_(not isinstance(mxsub, MSubArray))
        assert_(isinstance(mxsub, MaskedArray))
        assert_equal(mxsub._mask, m)
        #
        mxsub = masked_array(xsub, subok=True)
        assert_(isinstance(mxsub, MSubArray))
        assert_equal(mxsub.info, xsub.info)
        assert_equal(mxsub._mask, xsub._mask)
        #
        mxsub = asanyarray(xsub)
        assert_(isinstance(mxsub, MSubArray))
        assert_equal(mxsub.info, xsub.info)
        assert_equal(mxsub._mask, m) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:test_subclassing.py


注:本文中的numpy.testing.assert_方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。