Getting error: Cannot reshape array of size 122304 into shape (52,28,28)

Viewed 98236

I'm trying to reshape a numpy array as:

data3 = data3.reshape((data3.shape[0], 28, 28))

where data3 is:

[[54 68 66 ..., 83 72 58]
 [63 63 63 ..., 51 51 51]
 [41 45 80 ..., 44 46 81]
 ..., 
 [58 60 61 ..., 75 75 81]
 [56 58 59 ..., 72 75 80]
 [ 4  4  4 ...,  8  8  8]]

data3.shape is (52, 2352 )

But I keep getting the following error:

ValueError: cannot reshape array of size 122304 into shape (52,28,28)
Exception TypeError: TypeError("'NoneType' object is not callable",) in <function _remove at 0x10b6477d0> ignored

What is happening and how to fix this error?

UPDATE:

I'm doing this to obtain data3 that is being used above:

def image_to_feature_vector(image, size=(28, 28)):

    return cv2.resize(image, size).flatten()

data3 = np.array([image_to_feature_vector(cv2.imread(imagePath)) for imagePath in imagePaths])  

imagePaths contains paths to all the images in my dataset. I actually want to convert the data3 to a flat list of 784-dim vectors, however the

image_to_feature_vector 

function converts it to a 3072-dim vector!!

2 Answers
Related