我想将 MNIST 数据集从形状 (70000, 784) 重塑为 (70000, 28, 28),尝试了以下代码,但出现 TypeError:
类型错误:只有整数标量数组可以转换为标量索引
df = pd.read_csv('images.csv', sep=',', header=None)
x_data = np.array(df)
x_data = x_data.reshape(x_data[0], 28, 28)
Run Code Online (Sandbox Code Playgroud)
这有效,但速度很慢
data = np.array(df)
x_data = []
for d in data:
x_data.append(d.reshape(28,28))
x_data = np.array(x_data)
Run Code Online (Sandbox Code Playgroud)
numpy.reshape() 应该如何处理并且没有循环?曼尼谢谢!