ValueError: cannot reshape array of size 136415664 into shape (2734,132,126,1) I have a data set I loaded with cv2 but when I try to format it I get the above error. I start by moving the data into X_train and X_test (the loaded data is in x_train and x_test).
X_train = []
X_test = []

# Image matrices are different sizes so I am making them the same size
for i in range(len(x_train)-1):
  resized = cv2.resize(x_train[i], (img_width, img_height))
  X_train.append(resized)
for i in range(len(x_test)-1):
  resized = cv2.resize(x_test[i], (img_width, img_height))
  X_test.append(resized)

# Convert to numpy arrays
X_test = np.array(X_test)
X_train = np.array(X_train)

# Gather statistics 
print(X_train.shape)    # -&gt; (2734, 132, 126, 3)
print(X_train.size)     # -&gt; 136415664
print(len(X_train))     # -&gt; 2734

# Convert to black and white
X_train = X_train/ 255.
X_test = X_test/ 255.

# First line throws error
X_train = np.reshape(X_train, (len(X_train), img_height, img_width, 1))
X_test = np.reshape(X_test, (len(X_test), img_height, img_width, 1))

What am I doing wrong?
You need $2734 \times 132\times 126\times 1=45,471,888$ values in order to reshape into that tensor. Since you have $136,415,664$ values, the reshaping is impossible. If your fourth dimension is $4$, then the reshape will be possible.