# Reshape and normalize training datatrainX = train[:, 1:].reshape(train.shape[0],1,28, 28).astype( 'float32' )x_train = trainX / 255.0y_train = train[:,98]# Reshape and normalize test datatestX = test[:,1:].reshape(test.shape[0],1, 28, 28).astype( 'float32' )x_test = testX / 255.0y_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] 5ValueError: cannot reshape array of size 23760 into shape (240,1,28,28)
1 回答

LEATH
TA貢獻1936條經驗 獲得超7個贊
正如評論中已經提到的那樣,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),
以及它們的排列。
添加回答
舉報
0/150
提交
取消