title: Flattening of numpy array
body: <p>I'm performing data mining on images. Each pixel is treated as a data point. The image is read as follows:</p>
  
  <pre><code>im=Image.open('lena.bmp')
  im=numpy.array(im)
  print im.shape
  </code></pre>
  
  <p>Depending on whether the image is color or grayscale, im.shape is either (10,10, 3) or (10,10,1)</p>
  
  <p>After that, the image is flattened to a feature matrix as follows:</p>
  
  <p>if (10,10,3), then --->(100,3)</p>
  
  <p>if (10,10,1), then --->(100,1)</p>
  
  <p>How do I write a polymorphic function for this? My current approach is:</p>
  
  <pre><code>obs=reshape(im,(im.shape[0]*im.shape[1],1, im.size/(im.shape[0]*im.shape[1])))
  </code></pre>