title: How to update the elements of an array in a for loop
body: <p>I have an array called img. I want to check for the elements in the array which are negative, and then add 65536 to those elements. But for some reason, the array is not getting updated and when I print it, the old negative values are still being shown.</p>
  <pre><code>img = I
  imgx,imgy = img.shape
  
  for i in range(0,imgy):
      for j in range(0,imgx):
          if (img[i,j] &lt; 0):
              img[i,j] = img[i,j] + 65536
              print(i,j,img[i,j])
  </code></pre>
  <p>I also tried this:</p>
  <pre><code>            img[i,j] = += 65536
  </code></pre>
  <p>instead of this:</p>
  <pre><code>            img[i,j] = img[i,j] + 65536
  </code></pre>
  <p>in the loop, but to no avail. When I print the indices and the elements after updating, in either case, this is what I'm getting:</p>
  <pre><code>i   j   img[i,j]
  513 467 -31460
  513 468 -31981
  514 467 -30423
  514 468 -31172
  514 469 -32656
  515 467 -31554
  515 468 -31534
  515 469 -32114
  </code></pre>
  <p>I'm sure I'm missing something very basic here, but I'm kinda new to Python, and any help would be greatly appreciated.</p>
  <p>Thanks!</p>