i want to change a image(17x15) to 2d array with 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)
It change okay to 1D array but when i using reshape to make 2D array with list.reshape(17,15) got the error:
ValueError: total size of new array must be unchanged
The size is 17x15, and change to 1D array have 255 elements, so why the error appear and how to make it run normaly?
list.shape(which should be done afterlist = np.array(list))?list.shape. This will output the current shape of the array before you try to reshape it. It will hopefully give us some insight into your bug. Just add the lineprint(list.shape)beneath the linelist = np.array(list)and report the output of the print statement.list.shapeis(255, 1, 3)255 row, 1 col and 3 elements in each item?