weixin_38295174 2020-02-14 09:50 采纳率: 0%
浏览 1098

numpy reshape函数使用报错

我在学习使用tensorflow的时候遇到了一个报错,查了很久也没能解决问题

import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train,y_train),(x_test,y_test) = mnist.load_data()

print(x_train.shape,y_train.shape)
print(x_test.shape,y_test.shape)


import matplotlib.pyplot as plt
import numpy as np

np.pad(x_train,((0,0),(2,2),(2,2)),'constant',constant_values=0)

x_train = x_train.astype('float32')

x_train /= 255

x_train = x_train.reshape(x_train.shape[0],32,32,1)

获得报错 ValueError: cannot reshape array of size 47040000 into shape (60000,32,32,1)。
我是win10系统,下载的数据保存成mnist.npz,不知道为什么报错了,请各位大佬指点一下,谢谢!

  • 写回答

1条回答 默认 最新

  • admin_999 2020-02-18 12:59
    关注

    60000*32*32*1=61440000,你这数组元素总共都没这么多

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog