ValueError: cannot reshape array of size 23760 into shape (240,1,28,28)
ValueError: cannot reshape array of size 23760 into shape (240,1,28,28)
# Reshape and normalize training data
trainX = train[:, 1:].reshape(train.shape[0],1,28, 28).astype( 'float32' )
x_train = trainX / 255.0
y_train = train[:,98]
# Reshape and normalize test data
testX = test[:,1:].reshape(test.shape[0],1, 28, 28).astype( 'float32' )
x_test = testX / 255.0
y_test = test[:,98]
我尝试将我的 csv train_data 和 test_data 重塑为 3-D 矩阵,但出现错误:
ValueError Traceback (most recent call last)
<ipython-input-57-268af51a6b14> in <module>()
----> 1 trainX = train[:, 1:].reshape(train.shape[0],1,28, 28).astype( 'float32' )
2 x_train = trainX / 255.0
3
4 y_train = train[:,98]
5
ValueError: cannot reshape array of size 23760 into shape (240,1,28,28)
Error Report Screenshoot
正如评论中已经提到的,23760 != 240*1*28*28,因此无法重塑为该特定数组。事实上,28*28 连 23760 都不能整除,所以即使 train.shape[0]
换成其他东西,这也是行不通的。
假设 train.shape[0]
和 1
是您想要用于前两个维度的内容,最终维度的乘积需要为 23760/240 = 99。因为这不是一个平方数,这两个数字将不得不不同。 99 的质因数分解是 99 = 3*3*11,所以唯一可能的选项是
(240, 1, 1, 99), (240, 1, 3, 33), (240, 1, 9, 11),
及其排列。
# Reshape and normalize training data
trainX = train[:, 1:].reshape(train.shape[0],1,28, 28).astype( 'float32' )
x_train = trainX / 255.0
y_train = train[:,98]
# Reshape and normalize test data
testX = test[:,1:].reshape(test.shape[0],1, 28, 28).astype( 'float32' )
x_test = testX / 255.0
y_test = test[:,98]
我尝试将我的 csv train_data 和 test_data 重塑为 3-D 矩阵,但出现错误:
ValueError Traceback (most recent call last)
<ipython-input-57-268af51a6b14> in <module>()
----> 1 trainX = train[:, 1:].reshape(train.shape[0],1,28, 28).astype( 'float32' )
2 x_train = trainX / 255.0
3
4 y_train = train[:,98]
5
ValueError: cannot reshape array of size 23760 into shape (240,1,28,28)
Error Report Screenshoot
正如评论中已经提到的,23760 != 240*1*28*28,因此无法重塑为该特定数组。事实上,28*28 连 23760 都不能整除,所以即使 train.shape[0]
换成其他东西,这也是行不通的。
假设 train.shape[0]
和 1
是您想要用于前两个维度的内容,最终维度的乘积需要为 23760/240 = 99。因为这不是一个平方数,这两个数字将不得不不同。 99 的质因数分解是 99 = 3*3*11,所以唯一可能的选项是
(240, 1, 1, 99), (240, 1, 3, 33), (240, 1, 9, 11),
及其排列。