首页 > 编程语言 >python daal test

python daal test

时间:2023-05-30 22:05:25浏览次数:36  
标签:python res print moments low test daal data order

 

import os
import sys

from daal.algorithms import low_order_moments
from daal.data_management import FileDataSource, DataSourceIface
from daal.data_management import (readOnly, NumericTableIface, BlockDescriptor, BlockDescriptor_Float32, BlockDescriptor_Intc, packed_mask)

#utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
#if utils_folder not in sys.path:
#    sys.path.insert(0, utils_folder)
#from utils import printNumericTable

dataFileName = 'covcormoments_dense.csv'


def getArrayFromNumericTable(data_table):
    num_rows = data_table.getNumberOfRows()
    num_cols = data_table.getNumberOfColumns()
    layout = data_table.getDataLayout()
    data_table_dict = data_table.getDictionary()
    try:
        # see # https://software.intel.com/sites/products/documentation/doclib/daal/daal-user-and-reference-guides/daal_cpp_api/data__utils_8h_source.htm
        # for numeral values of types
        data_type = data_table_dict[0].indexType
    except:
        data_type = 1 # default to Float64

    if data_type == 0:
        block = BlockDescriptor_Float32()
    elif data_type in [2, 4, 6, 8]:
        block = BlockDescriptor_Intc()
    else:
        block = BlockDescriptor() # Use Float64 by default

    data_table.getBlockOfRows(0, num_rows, readOnly, block)
    retValue = block.getArray()
    data_table.releaseBlockOfRows(block)

    return retValue




def printResults(res):

     mi = getArrayFromNumericTable(res.get(low_order_moments.minimum))
     print (value of minimum:)
     print (mi)
#    print(res.get(low_order_moments.minimum))
#    print(res.get(low_order_moments.minimum))
#    print(res.get(low_order_moments.maximum))
#    print(res.get(low_order_moments.sum))
#    print(res.get(low_order_moments.sumSquares))
#    print(res.get(low_order_moments.sumSquaresCentered))
#    print(res.get(low_order_moments.mean))
#    print(res.get(low_order_moments.secondOrderRawMoment))
#    print(res.get(low_order_moments.variance))
#    print(res.get(low_order_moments.standardDeviation))
#    print(res.get(low_order_moments.variation))

if __name__ == "__main__":

    # Initialize FileDataSource to retrieve input data from .csv file
    dataSource = FileDataSource(
        dataFileName,
        DataSourceIface.doAllocateNumericTable,
        DataSourceIface.doDictionaryFromContext
    )

    # Retrieve the data from input file
    dataSource.loadDataBlock()

    # Create algorithm for computing low order moments in batch processing mode
    algorithm = low_order_moments.Batch()

    # Set input arguments of the algorithm
    algorithm.input.set(low_order_moments.data, dataSource.getNumericTable())

    # Get computed low order moments
    res = algorithm.compute()

    printResults(res)

  

标签:python,res,print,moments,low,test,daal,data,order
From: https://blog.51cto.com/u_11908275/6382272

相关文章

  • python二维数组初始化
    >>>a=[[0]*3foriinrange(3)]>>>a[[0,0,0],[0,0,0],[0,0,0]]>>>a[1][1]=121>>>a[[0,0,0],[0,121,0],[0,0,0]]>>>a[0][0]=11>>>a[[11,0,0],[0,121,0],[0,0,0]]>>>......
  • python pickle to json
    ref:https://gist.github.com/Samurais/567ebca0f59c612eb977065008aad867 '''Convertapklfileintojsonfile'''importsysimportosimportpickleimportjsondefconvert_dict_to_json(file_path):withopen(file_path,&......
  • python spark 求解最大 最小 平均 中位数
    rating_data_raw=sc.textFile("%s/ml-100k/u.data"%PATH)printrating_data_raw.first()num_ratings=rating_data_raw.count()print"Ratings:%d"%num_ratings#In[35]:rating_data=rating_data_raw.map(lambdaline:line.split(&quo......
  • AtCoder Beginner Contest 289(E,F)
    AtCoderBeginnerContest289(E,F)E(dijkstra)E这个题的大意就是有两个人,一个人在点\(1\),一个人在点\(n\),现在两个人要同时走(题目给出了点和边,还有每一个点的颜色),但是他们的下一步要到的点需要是颜色不同的,问\(1\)点出发的和\(n\)点出发的同时达到对方的起点的最短路径时哪......
  • Python爬取豆瓣电影Top250 + 数据可视化
    我的这篇博客的一些代码解释python大作业电影演员数据分析1.爬取数据1.1导入以下模块importosimportreimporttimeimportrequestsfrombs4importBeautifulSoupfromfake_useragentimportUserAgentfromopenpyxlimportWorkbook,load_workbook1.2获取每页......
  • 【python教程】map、多进程与进度条
    转载:【python教程】map、多进程与进度条-知乎(zhihu.com)今天讲讲我在实习中学到的一点python知识,核心内容是多进程,也即我们常说的并行计算。map首先提个问题,给出一个列表,对列表中的每个元素都平方,代码怎么写?最简单直观的方法自然就是for循环。alist=[1,2,3,4,5,6,......
  • 万年历python
    importtkinterastkimporttkinter.ttkasttkimportdatetimeimportcalendartoday_date=datetime.date.today()today_date_year=int(today_date.year)today_date_month=int(today_date.month)today_date_week=today_date.isocalendar()date_num_list......
  • AtCoder Beginner Contest 303
    A-SimilarString(abc303a)题目大意给定两个字符串,问这两个字符串是否相似。两个字符串相似,需要每个字母,要么完全相同,要么一个是1一个是l,要么一个是0一个是o解题思路按照题意模拟即可。可以将全部1换成l,全部0换成o,再判断相等。神奇的代码#include<bits/stdc++.h>us......
  • AtCoder Regular Contest 153 D Sum of Sum of Digits
    洛谷传送门AtCoder传送门又浪费一道好题我首先想的是,\(x\)显然最优取某些\(a_i\)往前进位时的值。然后就误以为\(x\)的取值是\(O(n\log_{10}V)\)的了……既然没发现什么性质,那就直接dp吧!设\(f_{d,i}\)为从低到高前\(d\)位,所有\(a_i\)进位之和为\(i\)。然......
  • 【python】with as语句
    读文件读写文件是最常见的IO操作。python内置了读写文件的函数,用法和C是兼容的。读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘,所以,读写文件就是请求操作系统打开一个文件对象(通常称为文件描述符),然后,通过操......