python - 绘制 MNIST 样本
问题描述
我正在尝试从 MNIST 数据集中绘制 10 个样本。每个数字一个。这是代码:
import sklearn
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
mnist = datasets.fetch_mldata('MNIST original')
y = mnist.target
X = mnist.data
for i in range(10):
im_idx = np.argwhere(y == i)[0]
print(im_idx)
plottable_image = np.reshape(X[im_idx], (28, 28))
plt.imshow(plottable_image, cmap='gray_r')
plt.subplot(2, 5, i + 1)
plt.plot()
出于某种原因,图中跳过了零位。
为什么?
解决方案
尝试这个:
import sklearn
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
mnist = datasets.fetch_mldata('MNIST original')
y = mnist.target
X = mnist.data
fig, ax = plt.subplots(2,5)
ax = ax.flatten()
for i in range(10):
im_idx = np.argwhere(y == i)[0]
print(im_idx)
plottable_image = np.reshape(X[im_idx], (28, 28))
ax[i].imshow(plottable_image, cmap='gray_r')
输出:
推荐阅读
- tensorflow - 为什么 tensorflow.contrib.framework.arg_scope 不适用于 tf.keras.layers?
- regex - 正则表达式简化问题
- batch-file - 在另一个驱动器中创建具有今天日期的文件夹
- matlab - 模拟终止,因为导数不是有限的
- php - 如何在 Laravel 5.6 中打印型号名称的计数和打印数量?
- google-compute-engine - 没有数据时的 StackDriver 警报
- python - 重复数据帧索引和合并列
- php - 在 macOS 上安装 Composer 时出错(JIT 编译失败)
- serialization - 序列化 Puppeteer 页面
- node.js - 如何在 HAProxy 和/或 NodeJS 流量中捕获/记录“突发”