edit: copying from my comment to give more context to the problem
One important thing I forgot to mention is my end goal is to add this as a column to a pandas dataframe. I was getting errors when trying to put the pixels array as is into dataframe due to more than one dimension.
I have a 32x32 image that I would like to flatten into a 1-D numpy array representing an object with the RGB values at that pixel.
img = Image.open(img_path) pixels = np.asarray(img) width, height = img.size pixels = pixels.reshape(width * height, 3)
Currently this is the best I can do without losing the grouping of RGB values in one object. With this implementation however I get a 2-D array with each element being an array of the RGB values like this.
shape: (1024, 3) [[255 255 255] [255 255 255] [255 255 255] ... [255 255 255] [255 255 255] [255 255 255]]
I would like my array to have shape (1024,1)
and for each element to be some object (maybe a tuple?) of RGB values. Thanks.
pixels = [tuple(x) for x in pixels]
. I'm not sure why you would want to do this though : you'll lose all the handy array-slicing capabilities of numpy. Or am I misunderstanding the question?