0

Is it possible to accelerate nested for loop in python?

I have to go through a whole image, pixel by pixel. Can I do something to speed it up?:

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
  • 1
    We can't help you without knowing anything about rgbMtx. Commented Apr 7, 2015 at 19:49

1 Answer 1

1

How about:

i, j, k = img[:, :, 0], img[:, :, 1], img[:, :, 2]
prob = rgMtx[i, j, k]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.