Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting this index error for an image size 882 x 786 - IndexError: index 786 is out of bounds for axis 0 with size 786

I have pasted the code below -
<pre lang="Python">
    for x in range(width):
       for y in range(height):
          saturation_pink = saturation_pink + result_pink[x][y][1]*(27 - result_pink[x][y][0])


What I have tried:

I tried the above code with 'width-1' and 'height-1' as well. But I still keep getting the same error
Posted
Updated 16-Jun-22 6:04am
Comments
Richard MacCutchan 16-Jun-22 15:22pm    
What are the values of width and height, and the dimensions of result_pink?

1 solution

Indexes in Python (like most other languages) start at zero, and run to the number of elements minus one.
So a three element array arr would have legitimate indexe of 0, 1, and 2 only - any other value is outside the bounds of the array and will cause an error.

In this case, you have probably muddled up width and height: should x be width related, or y, and do width and height contain the right values?
What did the debugger show you was going on?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900