Search code examples
pythonpandasdataframetensorflowreshape

ValueError: cannot reshape array of size 15525000 into shape (260,260) in Python?


I have a problem about reshaping dataframe for implementing CNN.

My dataframe shape : train.shape -> (230, 67502).

Then I wrote a code shown below.

Y_train = train["Label"]
X_train = train.drop(labels = ["Label"],axis = 1) 

When I run this code below for plotting some images by iloc, It throws an error

img = X_train.iloc[0].to_numpy()
img = np.pad(img, (0, (67600-img.shape[0])), 'constant').reshape((260, 260))
plt.imshow(img,cmap='gray')
plt.title(train.iloc[0,0])
plt.axis("off")
plt.show()

Then I normalize X_train

X_train = X_train / 255.0
print("x_train shape: ",X_train.shape)

When I reshape X_train , it throws an error

X_train = X_train.values.reshape(-1, 260, 260)
print("x_train shape: ",X_train.shape)

ValueError: cannot reshape array of size 15525000 into shape (260,260)

How can I fix the issue?


Solution

  • Solution :

    X_train = np.pad(X_train, ((0,0), (0, (67600-X_train.shape[1]))), 'constant').reshape(-1, 260, 260)