title: How do I make my numpy image take an alpha channel value in python
body: <p>I am trying to make the background of an image transparent. I have sectioned off all the part I want to be transparent in black. But python gives me an error message about only taking RBG. The error message I get is "cannot copy sequence with size 4 to array axis with dimension 3" So how do I make python recognize the alpha channel and allow me to manipulate it?</p>
  
  <pre><code>import matplotlib.pyplot as plt 
  import os.path
  import numpy as np 
  import PIL
  
  
  
  
  def mask(row, column) :
      for row in range(0, 383) :
          for column in range(0, 86) :
              img[row][column] = [0, 0, 0]
      for row in range(230, 383) :
          for column in range(0, 286) :
              img[row][column] = [0, 0, 0]
      for row in range(0, 50) :
          for column in range(0, 286) :
              img[row][column] = [0, 0, 0]
      for row in range(0, 383) :
          for column in range(199, 286) :
              img[row][column] = [0, 0, 0]
  
  
  
  
  directory = os.path.dirname(os.path.abspath(__file__)) 
  
  filename = os.path.join(directory, 'PicOfNick.jpg')
  
  img = plt.imread(filename)
  
  fig, ax = plt.subplots(1, 1)
  
  mask(283, 287) 
  np_img = np.array(img)
  width = len(img[0])
  height = len(img)
  for h in range(48, 230) :
      for w in range(84, 200) :
          if np_img[h][w][0] in range(50, 90) :
              np_img[h][w] = (0, 0, 0)
          if sum(np_img[h][w]) == 0 :
              np_img[h][w] = (0, 0, 0)
  
  
  
  ax.imshow(np_img, interpolation='none')
  
  fig.show()
  </code></pre>