title: Runtime Warning overflow encountered in ubyte_scalars
body: <pre><code>from PIL import Image
  import numpy as np 
  import matplotlib.pyplot as plt
  
  def threshold(imageArray):
      balanceAr = []
      newAr = imageArray
      for eachRow in imageArray:
          for eachPix in eachRow:
              avgNum = reduce(lambda x, y: x + y, eachPix[:3]) / len(eachPix[:3])
              balanceAr.append(avgNum)
      balance = reduce(lambda x, y: x + y, balanceAr) / len(balanceAr)
      for eachRow in newAr:
          for eachPix in eachRow:
              if reduce(lambda x, y: x + y, eachPix[:3]) / len(eachPix[:3]) &gt; balance:
                  eachPix[0] = 255
                  eachPix[1] = 255
                  eachPix[2] = 255
                  eachPix[3] = 255
              else:
                  eachPix[0] = 0
                  eachPix[1] = 0
                  eachPix[2] = 0
                  eachPix[3] = 255
      return newAr
  
  
  
  
  i = Image.open('images/numbers/0.1.png')
  iar = np.asarray(i)
  3iar = threshold(iar)
  
  i2 = Image.open('images/numbers/y0.4.png')
  iar2 = np.asarray(i2)
  #iar2 = threshold(iar2)
  
  i3 = Image.open('images/numbers/y0.5.png')
  iar3 = np.asarray(i3)
  #iar3 = threshold(iar3)
  
  i4 = Image.open('images/sentdex.png') 
  iar4 = np.asarray(i4)
  #iar4 = threshold(iar4)
  
  threshold(iar3)
  fig = plt.figure()
  ax1 = plt.subplot2grid((8,6), (0,0), rowspan = 4, colspan = 3)
  ax2 = plt.subplot2grid((8,6), (4,0), rowspan = 4, colspan = 3)
  ax3 = plt.subplot2grid((8,6), (0,3), rowspan = 4, colspan = 3)
  ax4 = plt.subplot2grid((8,6), (4,3), rowspan = 4, colspan = 3)
  
  ax1.imshow(iar)
  ax2.imshow(iar2)
  ax3.imshow(iar3)
  ax4.imshow(iar4)
  
  plt.show()
  </code></pre>
  
  <p>The error I'm getting:</p>
  
  <pre><code>Warning (from warnings module):
    File "C:\WinPython-32bit-2.7.9.5\python-2.7.9\Lib\idlelib\MuditPracticals\Image_Recognition\imagerec.py", line 11
      avgNum = reduce(lambda x, y: x + y, eachPix[:3]) / len(eachPix[:3])
  RuntimeWarning: overflow encountered in ubyte_scalars
  
  Warning (from warnings module):
    File "C:\WinPython-32bit-2.7.9.5\python-2.7.9\Lib\idlelib\MuditPracticals\Image_Recognition\imagerec.py", line 16
      if reduce(lambda x, y: x + y, eachPix[:3]) / len(eachPix[:3]) &gt; balance:
  RuntimeWarning: overflow encountered in ubyte_scalars
  
  Traceback (most recent call last):
    File "C:\WinPython-32bit-2.7.9.5\python-2.7.9\Lib\idlelib\MuditPracticals\Image_Recognition\imagerec.py", line 47, in &lt;module&gt;
      threshold(iar3)
    File "C:\WinPython-32bit-2.7.9.5\python-2.7.9\Lib\idlelib\MuditPracticals\Image_Recognition\imagerec.py", line 17, in threshold
      eachPix[0] = 255
  ValueError: assignment destination is read-only
  </code></pre>