并行映射2D python数组

时间:2013-12-22 20:04:46

标签: python arrays parallel-processing multiprocessing multicore

我可以根据包含每个像素的旧x,y坐标的元组的一维地图来分散图像中的像素

有没有办法更快地完成此操作,例如使用多个CPU coords或其他?

i=0
for x in range(1080)
    for y in range(720)
        result_img_arr[x][y] = input_img_arr[map_tuples[i]]
        i+=1

input_img_arr - 形状为(1080,720,3)

的图像数组

map_tuples - 包含x的y元组的一维数组(1080 * 720),y是从输入图像读取的坐标

2 个答案:

答案 0 :(得分:0)

不了解并行处理,但使用list-comprehension肯定会提高速度。有点像......

result_img_arr = [[map_tuples[y + x*720] 
                       for y in range(720)] 
                           for x in range(1080)]

答案 1 :(得分:0)

与numba的autojit应该大大提高速度。如果这仍然不够,你可以看一下pyopencl,但这样做可能有点复杂。

相关问题