显示使用python,numpy和matplot的mn位数

问题描述 投票:1回答:1

假设我在变量L中有MNIST位。

L[0].reshape(28,28)给我机会用matplot进行绘制:plt.matshow(L[0].reshape(28,28))

但是如果我想在5x5网格中绘制25个数字怎么办,我无法弄清楚如何将L [0:24]改组以使用matplot正确绘制它。

也许任何人都会知道如何做。

python numpy matplotlib mnist
1个回答
0
投票

一种方法是这样的:

fig, axes = plt.subplots(5,5)
for i, ax in enumerate(axes.ravel()):
    ax.imshow(L[i].reshape(28,28))

这样,您可以遍历子图。如果您想改变图表的顺序,可以使用np.random.permutation(25),这会置换您的索引:

fig, axes = plt.subplots(5,5)
for i, ax in zip(np.random.permutation(25), axes.ravel()):
    ax.imshow(L[i].reshape(28,28))
© www.soinside.com 2019 - 2024. All rights reserved.