下面的代码给了我正确的答案,但仅在数组 (plan和meas) 相对较小时才有效。当我尝试在我实际需要比较的数组上运行它时(每个 300x300),它需要很长时间(我不知道多长时间,因为我在 45 分钟后终止了它。)我只想迭代一个范围正在评估的索引周围的数组值 ( p)。我试图找到有关 nditer 标志的文档,'ranged'但找不到如何实现特定范围进行迭代。
p = np.nditer(plan, flags = ['multi_index','common_dtype'])
while not p.finished:
    gam_store = 100.0
    m = np.nditer(meas, flags = ['multi_index','common_dtype'])
    while not m.finished:
        dis_eval = np.sqrt(np.absolute(p.multi_index[0]-m.multi_index[0])**2 + np.absolute(p.multi_index[1]-m.multi_index[1])**2)           
        if dis_eval <= 6.0:
            a = (np.absolute(p[0] - m[0]) / maxdose) **2
            b = (dis_eval / gam_dist) **2
            gam_eval = np.sqrt(a + b)
            if gam_eval < gam_store:
                gam_store = gam_eval
        m.iternext()    
    gamma = np.insert(gamma, location, gam_store, 0)
    location = location + 1
    p.iternext()