Numpy 不再知道你的数组的大小,因为你已经重塑了它。你给它的形状是
60000, 784
,然后得到它的第二个元素,它的形状是784
.
如果您希望 numpy 将数组打印为 28x28 网格,您可以将形状指定为
60000, 28, 28
。
此外,您可能希望指定 numpy 输出的最大线宽,以便数组的每一行实际占用一行输出而不是溢出。
import numpy as np
... # Define your array in the first place
np.set_printoptions(linewidth=200) # Doesn't have to be 200, just anything that fits one row of the array
X_train.reshape(60000, 28, 28)[1] # Reshape to 28x28