为了账号安全,请及时绑定邮箱和手机立即绑定

ValueError:无法将大小为 23760 的数组重新整形为形状 (240,1,28,28)

ValueError:无法将大小为 23760 的数组重新整形为形状 (240,1,28,28)

慕妹3146593 2022-06-02 15:28:58
# 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),

以及它们的排列。


查看完整回答
反对 回复 2022-06-02
  • 1 回答
  • 0 关注
  • 262 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号