是否有可能加速python嵌套循环?

时间:2015-04-07 19:35:20

标签: python for-loop image-processing numpy nested-loops

是否有可能在python中加速嵌套for循环?

我必须逐个像素地浏览整个图像。我能做些什么来加快速度吗?:

sz =  np.shape(img)
prob = np.zeros((sz[0],sz[1]))
for i in range(sz[0]):
    for j in range(sz[1]):
        prob[i, j] = rgbMtx[img[i, j, 0], img[i, j, 1], img[i, j, 2]]

1 个答案:

答案 0 :(得分:1)

怎么样:

i, j, k = img[:, :, 0], img[:, :, 1], img[:, :, 2]
prob = rgMtx[i, j, k]