使用多个参数的循环的并行化

2024-04-18 23:59:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编程一个数据样本的核密度估计,所以我有一个循环。我想使用多处理的Pool()函数

我想使用map()函数定义一个计算循环的函数

def bouclekde1d(i,X,energy):

    Z[i]=kergauss1d(X[i],energy1,h)

    return Z

def plotkde1d(energy1,taille):
    n=len(energy1)
    h=np.std(energy1)*n**(-1/(4+1))#some formula
    X=np.linspace(min(energy1),max(energy1),100)#discretise an interval
    lenx=len(X)
    Z=np.zeros(lenx)#initialisation of the matrix

 #    for i in range(0,lenx):
 #        Z[i]=kergauss1d(X[i],energy1,h)
 #How does it work?
 pool=Pool()
 pool.map(bouclekde1d(i,X,energy1,h),range(0,lenx))

我希望通过多处理来计算Z

谢谢


Tags: 数据函数maplendef编程nprange