• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python type_check.nan_to_num函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.lib.type_check.nan_to_num函数的典型用法代码示例。如果您正苦于以下问题:Python nan_to_num函数的具体用法?Python nan_to_num怎么用?Python nan_to_num使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_float

 def test_float(self):
     vals = nan_to_num(1.0)
     assert_all(vals == 1.0)
     assert_equal(type(vals), np.float_)
     vals = nan_to_num(1.1, nan=10, posinf=20, neginf=30)
     assert_all(vals == 1.1)
     assert_equal(type(vals), np.float_)
开发者ID:anntzer,项目名称:numpy,代码行数:7,代码来源:test_type_check.py


示例2: test_array

 def test_array(self):
     vals = nan_to_num([1])
     assert_array_equal(vals, np.array([1], int))
     assert_equal(type(vals), np.ndarray)
     vals = nan_to_num([1], nan=10, posinf=20, neginf=30)
     assert_array_equal(vals, np.array([1], int))
     assert_equal(type(vals), np.ndarray)
开发者ID:anntzer,项目名称:numpy,代码行数:7,代码来源:test_type_check.py


示例3: test_complex_good

 def test_complex_good(self):
     vals = nan_to_num(1+1j)
     assert_all(vals == 1+1j)
     assert_equal(type(vals), np.complex_)
     vals = nan_to_num(1+1j, nan=10, posinf=20, neginf=30)
     assert_all(vals == 1+1j)
     assert_equal(type(vals), np.complex_)
开发者ID:anntzer,项目名称:numpy,代码行数:7,代码来源:test_type_check.py


示例4: test_integer

 def test_integer(self):
     vals = nan_to_num(1)
     assert_all(vals == 1)
     assert_equal(type(vals), np.int_)
     vals = nan_to_num(1, nan=10, posinf=20, neginf=30)
     assert_all(vals == 1)
     assert_equal(type(vals), np.int_)
开发者ID:anntzer,项目名称:numpy,代码行数:7,代码来源:test_type_check.py


示例5: test_complex_bad

 def test_complex_bad(self):
     with np.errstate(divide='ignore', invalid='ignore'):
         v = 1 + 1j
         v += np.array(0+1.j)/0.
     vals = nan_to_num(v)
     # !! This is actually (unexpectedly) zero
     assert_all(np.isfinite(vals))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:7,代码来源:test_type_check.py


示例6: calcN

def calcN(classKernels, trainLabels):
    N = zeros((len(trainLabels), len(trainLabels)))
    for i, l in enumerate(unique(trainLabels)):
        numExamplesWithLabel = len(where(trainLabels == l)[0])
        Idiff = identity(numExamplesWithLabel, Float64) - (1.0 / numExamplesWithLabel) * ones(numExamplesWithLabel, Float64)
        firstDot = dot(classKernels[i], Idiff)
        labelTerm = dot(firstDot, transpose(classKernels[i]))
        N += labelTerm
    N = nan_to_num(N)
    #make N more numerically stable
    #if I had more time, I would train this parameter, but I don't
    additionToN = ((mean(diag(N)) + 1) / 100.0) * identity(N.shape[0], Float64) 
    N += additionToN
            
    #make sure N is invertable
    for i in range(1000):
        try:
            inv(N)
        except LinAlgError:
            #doing this to make sure the maxtrix is invertable
            #large value supported by section titled
            #"numerical issues and regularization" in the paper
            N += additionToN

    return N
开发者ID:Primer42,项目名称:TuftComp136,代码行数:25,代码来源:main.py


示例7: test_generic

    def test_generic(self):
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = nan_to_num(np.array((-1., 0, 1))/0.)
        assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
        assert_(vals[1] == 0)
        assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))

        # perform the same test but in-place
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = np.array((-1., 0, 1))/0.
        result = nan_to_num(vals, copy=False)

        assert_(result is vals)
        assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
        assert_(vals[1] == 0)
        assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
开发者ID:minrk,项目名称:numpy,代码行数:16,代码来源:test_type_check.py


示例8: test_complex_bad2

 def test_complex_bad2(self):
     with np.errstate(divide='ignore', invalid='ignore'):
         v = 1 + 1j
         v += np.array(-1+1.j)/0.
     vals = nan_to_num(v)
     assert_all(np.isfinite(vals))
     assert_equal(type(vals), np.complex_)
开发者ID:anntzer,项目名称:numpy,代码行数:7,代码来源:test_type_check.py


示例9: test_do_not_rewrite_previous_keyword

 def test_do_not_rewrite_previous_keyword(self):
     # This is done to test that when, for instance, nan=np.inf then these 
     # values are not rewritten by posinf keyword to the posinf value.
     with np.errstate(divide='ignore', invalid='ignore'):
         vals = nan_to_num(np.array((-1., 0, 1))/0., nan=np.inf, posinf=999)
     assert_all(np.isfinite(vals[[0, 2]]))
     assert_all(vals[0] < -1e10)
     assert_equal(vals[[1, 2]], [np.inf, 999])
     assert_equal(type(vals), np.ndarray)
开发者ID:anntzer,项目名称:numpy,代码行数:9,代码来源:test_type_check.py


示例10: trainKFD

def trainKFD(trainKernel, trainLabels):
    classKernels = getClassKernels(trainKernel, trainLabels)
    M = calcM(classKernels, trainLabels)
    N = calcN(classKernels, trainLabels)
    '''
    print "train kernel:",trainKernel
    print "Class kernels:", classKernels
    print "M",M
    print "N",N
    '''
    try:
        solutionMatrix = dot(inv(N), M)
    except LinAlgError:
        #if we get a singular matrix here, there isn't much we can do about it
        #just skip this configuration
        solutionMatrix = identity(N.shape[0], Float64)
        
    solutionMatrix = nan_to_num(solutionMatrix)
    
    eVals, eVects = eig(solutionMatrix)
    #find the 'leading' term i.e. find the eigenvector with the highest eigenvalue
    alphaVect = eVects[:, absolute(eVals).argmax()].real.astype(Float64)
    trainProjections = dot(trainKernel, alphaVect)
    '''
    print 'alpha = ', alphaVect
    print 'train kernel = ', trainKernel
    print 'train projction = ', trainProjections
    '''     
    #train sigmoid based on evaluation accuracy
    #accuracyError = lambda x: 100.0 - evaluations(trainLabels, classifyKFDValues(trainProjections, *list(x)))[0]
    accuracyError = lambda x: 100.0 - evaluations(trainLabels, classifyKFDValues(trainProjections, *x))[0]
    #get an initial guess by brute force
    #ranges = ((-100, 100, 1), (-100, 100, 1))
    #x0 = brute(accuracyError, ranges)
    
    #popt = minimize(accuracyError, x0.tolist(), method="Powell").x

    rc = LSFAIL
    niter = 0
    i = 0
    while rc in (LSFAIL, INFEASIBLE, CONSTANT, NOPROGRESS, USERABORT, MAXFUN) or niter <= 1:
        if i == 10:
            break
        #get a 'smarter' x0
        #ranges = ((-1000, 1000, 100), (-1000, 1000, 100))
        ranges = ((-10**(i + 1), 10**(i + 1), 10**i),) * 2
        x0 = brute(accuracyError, ranges)
        (popt, niter, rc) = fmin_tnc(accuracyError, x0, approx_grad=True)
        #popt = fmin_tnc(accuracyError, x0.tolist(), approx_grad=True)[0]
        i += 1
    
    return (alphaVect, popt)
开发者ID:Primer42,项目名称:TuftComp136,代码行数:52,代码来源:main.py


示例11: test_generic

    def test_generic(self):
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = nan_to_num(np.array((-1., 0, 1))/0.)
        assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
        assert_(vals[1] == 0)
        assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
        assert_equal(type(vals), np.ndarray)
        
        # perform the same tests but with nan, posinf and neginf keywords
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = nan_to_num(np.array((-1., 0, 1))/0., 
                              nan=10, posinf=20, neginf=30)
        assert_equal(vals, [30, 10, 20])
        assert_all(np.isfinite(vals[[0, 2]]))
        assert_equal(type(vals), np.ndarray)

        # perform the same test but in-place
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = np.array((-1., 0, 1))/0.
        result = nan_to_num(vals, copy=False)

        assert_(result is vals)
        assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
        assert_(vals[1] == 0)
        assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
        assert_equal(type(vals), np.ndarray)
        
        # perform the same test but in-place
        with np.errstate(divide='ignore', invalid='ignore'):
            vals = np.array((-1., 0, 1))/0.
        result = nan_to_num(vals, copy=False, nan=10, posinf=20, neginf=30)

        assert_(result is vals)
        assert_equal(vals, [30, 10, 20])
        assert_all(np.isfinite(vals[[0, 2]]))
        assert_equal(type(vals), np.ndarray)
开发者ID:anntzer,项目名称:numpy,代码行数:36,代码来源:test_type_check.py


示例12: test_complex_good

 def test_complex_good(self):
     vals = nan_to_num(1+1j)
     assert_all(vals == 1+1j)
开发者ID:dyao-vu,项目名称:meta-core,代码行数:3,代码来源:test_type_check.py


示例13: test_integer

 def test_integer(self):
     vals = nan_to_num(1)
     assert_all(vals == 1)
     vals = nan_to_num([1])
     assert_array_equal(vals, np.array([1], np.int))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:5,代码来源:test_type_check.py


示例14: test_generic

 def test_generic(self):
     with np.errstate(divide='ignore', invalid='ignore'):
         vals = nan_to_num(np.array((-1., 0, 1))/0.)
     assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0]))
     assert_(vals[1] == 0)
     assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2]))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:6,代码来源:test_type_check.py


示例15: test_integer

 def test_integer(self):
     vals = nan_to_num(1)
     assert_all(vals == 1)
开发者ID:Aliases,项目名称:dissect,代码行数:3,代码来源:test_type_check.py


示例16: test_complex_bad2

 def test_complex_bad2(self):
     with np.errstate(divide="ignore", invalid="ignore"):
         v = 1 + 1j
         v += np.array(-1 + 1.0j) / 0.0
     vals = nan_to_num(v)
     assert_all(np.isfinite(vals))
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:6,代码来源:test_type_check.py


示例17: polyKernel

def polyKernel(x,y, gamma, coef, degree):
    if gamma == 0:
        gamma = .01
    ret = (gamma * dot(x, transpose(y)) + coef) ** degree
    ret = nan_to_num(ret)
    return ret
开发者ID:Primer42,项目名称:TuftComp136,代码行数:6,代码来源:main.py


示例18: test_array

 def test_array(self):
     vals = nan_to_num([1])
     assert_array_equal(vals, np.array([1], int))
     assert_equal(type(vals), np.ndarray)
开发者ID:Nodd,项目名称:numpy,代码行数:4,代码来源:test_type_check.py


示例19: test_integer

 def test_integer(self):
     vals = nan_to_num(1)
     assert_all(vals == 1)
     assert_equal(type(vals), np.int_)
开发者ID:Nodd,项目名称:numpy,代码行数:4,代码来源:test_type_check.py


示例20: test_complex_good

 def test_complex_good(self):
     vals = nan_to_num(1+1j)
     assert_all(vals == 1+1j)
     assert_equal(type(vals), np.complex_)
开发者ID:Nodd,项目名称:numpy,代码行数:4,代码来源:test_type_check.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.safe_eval函数代码示例发布时间:2022-05-27
下一篇:
Python type_check.isreal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap