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

Python shape_base.array_split函数代码示例

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

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



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

示例1: __init__

 def __init__(self, numFolds, data, labels):
     self._numFolds = numFolds
     self._curFold = 0
     self._trainData = array_split(data, self._numFolds)
     self._testData = None
     self._trainLabels = array_split(labels, self._numFolds)
     self._testLabels = None
开发者ID:Primer42,项目名称:TuftComp136,代码行数:7,代码来源:main.py


示例2: test_integer_split_2D_rows

    def test_integer_split_2D_rows(self):
        a = np.array([np.arange(10), np.arange(10)])
        res = array_split(a, 3, axis=0)
        tgt = [np.array([np.arange(10)]), np.array([np.arange(10)]), np.zeros((0, 10))]
        compare_results(res, tgt)
        assert_(a.dtype.type is res[-1].dtype.type)

        # Same thing for manual splits:
        res = array_split(a, [0, 1, 2], axis=0)
        tgt = [np.zeros((0, 10)), np.array([np.arange(10)]), np.array([np.arange(10)])]
        compare_results(res, tgt)
        assert_(a.dtype.type is res[-1].dtype.type)
开发者ID:SoumitraAgarwal,项目名称:numpy,代码行数:12,代码来源:test_shape_base.py


示例3: crossValidation

def crossValidation(numFolds, data, labels, algorithm, accuracyList, learningCurveList, numLearningCurveIterations, learningCurveIndexMod):
    dataFolds = array_split(data, numFolds)
    labelFolds = array_split(labels, numFolds)
    for testIndex in range(numFolds):
        print testIndex,
        testData = dataFolds.pop(testIndex)
        testLabels = labelFolds.pop(testIndex)
        trainData = vstack(dataFolds)
        trainLabels = hstack(labelFolds)
        accuracyList.append(algorithm(trainData, trainLabels, testData, testLabels))
        learningCurve(algorithm, learningCurveList, trainData, trainLabels, testData, testLabels, numLearningCurveIterations, learningCurveIndexMod)
        dataFolds.insert(testIndex, testData)
        labelFolds.insert(testIndex, testLabels)
    print ''
开发者ID:Primer42,项目名称:TuftComp136,代码行数:14,代码来源:main.py


示例4: test_index_split_high_bound

 def test_index_split_high_bound(self):
     a = np.arange(10)
     indices = [0, 5, 7, 10, 12]
     res = array_split(a, indices, axis=-1)
     desired = [np.array([]), np.arange(0, 5), np.arange(5, 7),
                np.arange(7, 10), np.array([]), np.array([])]
     compare_results(res, desired)
开发者ID:ContinuumIO,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例5: test_index_split_simple

 def test_index_split_simple(self):
     a = np.arange(10)
     indices = [1, 5, 7]
     res = array_split(a, indices, axis=-1)
     desired = [np.arange(0, 1), np.arange(1, 5), np.arange(5, 7),
                np.arange(7, 10)]
     compare_results(res, desired)
开发者ID:ContinuumIO,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例6: test_integer_split_2D_cols

 def test_integer_split_2D_cols(self):
     a = np.array([np.arange(10), np.arange(10)])
     res = array_split(a, 3, axis=-1)
     desired = [np.array([np.arange(4), np.arange(4)]),
                np.array([np.arange(4, 7), np.arange(4, 7)]),
                np.array([np.arange(7, 10), np.arange(7, 10)])]
     compare_results(res, desired)
开发者ID:ContinuumIO,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例7: test_integer_split_2D_rows_greater_max_int32

 def test_integer_split_2D_rows_greater_max_int32(self):
     a = np.broadcast_to([0], (1 << 32, 2))
     res = array_split(a, 4)
     chunk = np.broadcast_to([0], (1 << 30, 2))
     tgt = [chunk] * 4
     for i in range(len(tgt)):
         assert_equal(res[i].shape, tgt[i].shape)
开发者ID:Horta,项目名称:numpy,代码行数:7,代码来源:test_shape_base.py


示例8: test_integer_split_2D_default

 def test_integer_split_2D_default(self):
     """ This will fail if we change default axis
     """
     a = np.array([np.arange(10), np.arange(10)])
     res = array_split(a, 3)
     tgt = [np.array([np.arange(10)]), np.array([np.arange(10)]), np.zeros((0, 10))]
     compare_results(res, tgt)
     assert_(a.dtype.type is res[-1].dtype.type)
开发者ID:SoumitraAgarwal,项目名称:numpy,代码行数:8,代码来源:test_shape_base.py


示例9: test_integer_split

    def test_integer_split(self):
        a = np.arange(10)
        res = array_split(a, 1)
        desired = [np.arange(10)]
        compare_results(res, desired)

        res = array_split(a, 2)
        desired = [np.arange(5), np.arange(5, 10)]
        compare_results(res, desired)

        res = array_split(a, 3)
        desired = [np.arange(4), np.arange(4, 7), np.arange(7, 10)]
        compare_results(res, desired)

        res = array_split(a, 4)
        desired = [np.arange(3), np.arange(3, 6), np.arange(6, 8),
                   np.arange(8, 10)]
        compare_results(res, desired)

        res = array_split(a, 5)
        desired = [np.arange(2), np.arange(2, 4), np.arange(4, 6),
                   np.arange(6, 8), np.arange(8, 10)]
        compare_results(res, desired)

        res = array_split(a, 6)
        desired = [np.arange(2), np.arange(2, 4), np.arange(4, 6),
                   np.arange(6, 8), np.arange(8, 9), np.arange(9, 10)]
        compare_results(res, desired)

        res = array_split(a, 7)
        desired = [np.arange(2), np.arange(2, 4), np.arange(4, 6),
                   np.arange(6, 7), np.arange(7, 8), np.arange(8, 9),
                   np.arange(9, 10)]
        compare_results(res, desired)

        res = array_split(a, 8)
        desired = [np.arange(2), np.arange(2, 4), np.arange(4, 5),
                   np.arange(5, 6), np.arange(6, 7), np.arange(7, 8),
                   np.arange(8, 9), np.arange(9, 10)]
        compare_results(res, desired)

        res = array_split(a, 9)
        desired = [np.arange(2), np.arange(2, 3), np.arange(3, 4),
                   np.arange(4, 5), np.arange(5, 6), np.arange(6, 7),
                   np.arange(7, 8), np.arange(8, 9), np.arange(9, 10)]
        compare_results(res, desired)

        res = array_split(a, 10)
        desired = [np.arange(1), np.arange(1, 2), np.arange(2, 3),
                   np.arange(3, 4), np.arange(4, 5), np.arange(5, 6),
                   np.arange(6, 7), np.arange(7, 8), np.arange(8, 9),
                   np.arange(9, 10)]
        compare_results(res, desired)

        res = array_split(a, 11)
        desired = [np.arange(1), np.arange(1, 2), np.arange(2, 3),
                   np.arange(3, 4), np.arange(4, 5), np.arange(5, 6),
                   np.arange(6, 7), np.arange(7, 8), np.arange(8, 9),
                   np.arange(9, 10), np.array([])]
        compare_results(res, desired)
开发者ID:ContinuumIO,项目名称:numpy,代码行数:60,代码来源:test_shape_base.py


示例10: sorted

         #remove ignored columns and class column, in reverse sorted order
         #do it in reverse sorted order so the indexes stay correct
         for removeCol in sorted(ignoreColList + [classCol], reverse=True):
             if removeCol == classCol:
                 label = features.pop(removeCol)
             else:
                 features.pop(removeCol)
         datasetDict[label].append(features)
     origDataFile.close()
     
 
     #make it into a 2 class problem by lumping classes together
     #don't have rhyme or reason - don't want to favor one class or another, or make our data artificially clean
     numOrigClasses = len(datasetDict.keys())
     #split into 2, possibly unequal, groups of class labels
     newClassMap = array_split(datasetDict.keys(), 2)
     
     #reorganize the data
     dataWithNewLabelMap = defaultdict(list)
     
     for newClassLabel, oldClassLabelList in enumerate(newClassMap):
         for oldClassLabel in oldClassLabelList:
             for featureRow in datasetDict[oldClassLabel]:
                 dataWithNewLabelMap[newClassLabel].append(featureRow)
     
     #make the two datasets the same size
     dataWithNewLabelTupleList = []
     minClassSize = min([len(x) for x in dataWithNewLabelMap.values()])
     for newClassLabel, featureRowList in dataWithNewLabelMap.iteritems():
         for featureRow in featureRowList[:minClassSize]:
             dataWithNewLabelTupleList.append((featureRow, newClassLabel))
开发者ID:Primer42,项目名称:TuftComp136,代码行数:31,代码来源:data_to_csv.py


示例11: getDataSets

 datasets = getDataSets(dataDir, ['ionosphere', 'iris', 'wine'])
 #datasets = getDataSets(dataDir, ['by_hand'])
 #datasets = getDataSets(dataDir, ['ionosphere'])
 
 
 
 tp = ThreadPool(4)
     
 for name, (data, labels) in datasets.iteritems():
     datasetOutDir = getDatasetOutDir(outDir, name)
     print "Computing on", name
 
     #do a split into overall test and overall train
     overallTestTrainRatio = 1.0 / 3.0
     overallTestTrainSplitIndex = array([int(overallTestTrainRatio * len(data))])
     overallTestData, overallTrainData = array_split(data, array([overallTestTrainSplitIndex]))
     overallTestLabels, overallTrainLabels = array_split(labels, overallTestTrainSplitIndex)        
             
     #test a whole bunch of generic kernels on the overall split data
     fileIdentifier = 'overall'
     #print "train:", overallTrainData
     #print "test:", overallTestData
            
     compareAlgorithmsOnSameKernels(tp, overallTrainData, overallTrainLabels, overallTestData, overallTestLabels, name, fileIdentifier)
     
     #now, try to find an optimal kernel for either svm or kfd
     #do it for each kernel type
     numOptimizationFolds = 3
     fileIdentifier = 'optimized'
     compareAlgorithmsOnOptimizedKernel(tp, overallTrainData, overallTrainLabels, overallTestData, overallTestLabels, numOptimizationFolds, datasetOutDir, name, fileIdentifier)
     
开发者ID:Primer42,项目名称:TuftComp136,代码行数:30,代码来源:main.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shape_base.dstack函数代码示例发布时间:2022-05-27
下一篇:
Python shape_base.apply_along_axis函数代码示例发布时间: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