title: PIL's Imagefromarray resulting in error when trying to convert from numpy array
body: <p>I have a simple image saved in the .bmp format.<a href="https://i.stack.imgur.com/W6JAp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W6JAp.png" alt="enter image description here"></a></p>
  
  <p>I'm using the following code to convert the pixels values into an np.array</p>
  
  <pre><code>from PIL import Image
  im = Image.open('C:\Desktop\sample_pic.bmp') 
  pix = im.load()
  im.show()
  pixels=np.array(im.getdata())
  </code></pre>
  
  <p>The array shape is </p>
  
  <pre><code>(423099L,)
  </code></pre>
  
  <p>Now for simplicity purposes I"m going to use these array values when trying PIL's Imagefromarray function. </p>
  
  <pre><code>  im = Image.fromarray(pixels, mode ='P')
  </code></pre>
  
  <p>However, when running this code, I'm running into an error. </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#51&gt;", line 1, in &lt;module&gt;
      Image.fromarray(pixels, mode ='P')
    File "C:\Python27\lib\site-packages\PIL\Image.py", line 2180, in fromarray
      size = shape[1], shape[0]
  IndexError: tuple index out of range
  </code></pre>
  
  <p>So I tried changing the shape of the array, with the following code</p>
  
  <pre><code>x = pixels.reshape(1, 423099)
  im =Image.fromarray(x, mode = 'P')
  </code></pre>
  
  <p>I'm able to run the code <em>now</em> without raising an error.
  However when I run 
  <code>im.show()</code> to see the pic..</p>
  
  <p>I'm getting a pic with only a line running through the middle and not my original pic. </p>
  
  <p><a href="https://i.stack.imgur.com/2bWqB.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2bWqB.gif" alt="enter image description here"></a></p>
  
  <p>I want to be able to convert my original pic's values into an array, and then take the same array and be able to convert it to the imageformat .bmp using PIL's Imagefromarray. </p>
  
  <p>Thanks.  </p>
  
  <p>EDIT: Even if I change the array to its original shape of 887 x 477 I'm getting a totally different picture from the original. </p>
  
  <pre><code> y = pixels.reshape(887,477)
  im = Image.fromarray(y, mode = 'P')
  im.show()
  </code></pre>
  
  <p>resulting pic is</p>
  
  <p><a href="https://i.stack.imgur.com/SRfAE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SRfAE.png" alt="enter image description here"></a></p>