Can't reshape array with numpy
<p>i want to change a image(17x15) to 2d array with code:</p>

<pre><code>from PIL import Image
import numpy as np

list = []
im = Image.open('plus1.jpg')
row,col =  im.size
print(row,col)
for i in range (row):
   for j in range (col):
        r, g, b = im.getpixel((i, j))
        list.append([r,g,b]) 
print(list)
print(len(list))
list = np.array(list)
print(list)
list.reshape(17,15)
</code></pre>

<p>It change okay to 1D array but when i using reshape to make 2D array with <code>list.reshape(17,15)</code> got the error:</p>

<pre><code>ValueError: total size of new array must be unchanged
</code></pre>

<p>The size is 17x15, and change to 1D array have 255 elements, so why the error appear and how to make it run normaly?</p>

<p>Your image is 17x15, so there are 255 pixels. For each pixel, there are three color values (r,g,b). This means that your array <code>list</code> has shape <code>(255,1,3)</code>. This means that it contains 755 elements, and an error is raised when you try to reshape it to <code>(17,15)</code>, which does not preserve the number of elements. To obtain an array that has the first two dimensions the same as your image <code>(17,15)</code>, and a third axis that contains the rgb values, you should write:</p>

<pre><code>np.reshape(list, (17,15,3) )
</code></pre>

python arrays numpy