2个回答
# ipython@python3环境
import pandas as pd
import numpy as np
with open('~/train.csv') as f:
data = pd.read_csv(f)
X = data.drop(['y','id'], axis=1)
X = np.array(X)
# 每一行代表一张图片,选取第一行。
pic1 = X[1]
# 图片分辨率是40*40
pic1 = pic1.reshape((40, 40))
# 绘图
%matplotlib inline
from matplotlib import pyplot as plt
# 传入cmap='gray'指定图片为黑白
plt.imshow(pic1, cmap='gray')
另外补充一下,如果是彩色图片,在reshape的时候需要设置成三维,分别代表每个像素点RGB三种配色的取值:
pic1.reshape((height, width, 3))
您的回答非常具体!谢谢!
-
剪叔
2017-12-29 23:48
import matplotlib.pyplot as plt
plt.imshow(my_figure, cmap=plt.cm.binary)
plt.show()