Skip to content Skip to sidebar Skip to footer

Valueerror: Could Not Broadcast Input Array From Shape (22500,3) Into Shape (1)

I relied on the code mentioned, here, but with minor edits. The version that I have is as follows: import numpy as np import _pickle as cPickle from PIL import Image import sys,os

Solution 1:

To understand the structure of traindata, I replaced your pixels.append(pix) with pixels.append(pix[np.ix_([1,2,3],[0,1,2])]) to have some toy example. Then I get that traindata is

[array([[[16, 13, 15],
         [16, 13, 15],
         [16, 13, 15]]]), array([1])]

When you tried to transform traindata to numpy array you got error as it consists of subarrays of different sizes. You can either save each one of the subarrays in a separate numpy array, or you can do it like that:

traindata = np.array([traindata[0][0],traindata[1]], dtype=object)

By using dtype=object, you can create numpy array consists of elements of different sizes.

Post a Comment for "Valueerror: Could Not Broadcast Input Array From Shape (22500,3) Into Shape (1)"