如何并行化这个耗时的循环

how to parallelize this time consuming loops

am Traying 查找图像块之间的距离矩阵矩阵的每一项代表图像块和其他块之间的距离我的代码运行正常但是它消耗了很多时间我需要并行化循环

def calchellinger(glcm):
    tmp = np.zeros((glcm.shape[0],glcm.shape[1]))
    for i in range(glcm.shape[0]):
        for j in range(glcm.shape[1]):
            sum = 0 
            for x in range(glcm.shape[0]):                
                for y in range(glcm.shape[1]):
                    sum  = sum + hellinger(np.array(glcm[i,j]).flatten(), np.array(glcm[x,y]).flatten())                    
                tmp[i,j] = sum
    return tmp
def hellinger(p,q):
   return sum([(np.sqrt(t[0])-np.sqrt(t[1]))*(np.sqrt(t[0])-np.sqrt(t[1]))\
                for t in zip(p,q)])/np.sqrt(2.)

您可以在 joblib (https://joblib.readthedocs.io/en/latest/parallel.html) 中尝试 Embarrassingly parallel for loops。这是制动循环和 运行 并行

的简单方法