title: Reshape the image matrix in python
body: <p>I want first to convert the original image (where the shape and dtype is <code>((1024, 1024, 3), dtype('uint8'))</code>) into 1D array so that I can enter that 1D array into the training set as one observation.</p>
  
  <p>Now I want to convert that 1D array into it's original form.</p>
  
  <p>For converting original image into 1D array I used <code>flatten()</code> function available in numpy. Below is code:</p>
  
  <pre><code>In[80]: t = misc.imread('b.png') #to read the image
  
  In[81]: t.shape, t.dtype
  Out[81]: ((1024, 1024, 3), dtype('uint8'))
  
  #To convert the above image into 1D array
  
  In[82]: t.flatten()
  Out[82]: array([  5,  40, 121, ..., 130, 110,  89], dtype=uint8)
  </code></pre>
  
  <p>Now I want to convert the above matrix(result from <code>t.flattern()</code>) into the original matrix(i.e <code>(1024,1024,3)</code> in shape). </p>
  
  <p>Please tell me what should I do. </p>
  
  <p>Update:
  I checked the shape of <code>t.flatten</code> and it comes out to be</p>
  
  <pre><code>In[86]: p=t.flatten()
  In[87]: p.shape
  Out[86]:(6291456,) 
  </code></pre>
  
  <p>But 6291456=(1024*1024*3* <strong>2</strong>). Now I am confused that from where does this extra term(i.e <strong>2</strong>) comes out.</p>
  
  <p>I also used reshape command but error comes out when I executed the command.</p>
  
  <pre><code>l=p.reshape(1024,1024,3)
  
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-89-b1ab41666df7&gt; in &lt;module&gt;()
  ----&gt; 1 l=p.reshape(1024,1024,3)
  
  ValueError: total size of new array must be unchanged
  </code></pre>