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 a toy example. Then I get that traindata is
[array([[[16, 13, 15], [16, 13, 15], [16, 13, 15]]]), array([1])]
When you tried to convert the traindata array to numpy, you got an error, because it consists of subarrays of different sizes. You can either save each of the subarrays in a separate numpy array, or do it this way:
traindata = np.array([traindata[0][0],traindata[1]], dtype=object)
Using dtype=object , you can create a numpy array consisting of elements of different sizes.
source share