plt图像保存到pdf文件
# plt图保存到pdf文件
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages('test.pdf') as pdf:
plt.plot()
pdf.savefig()
plt.close()
# 写入pkl文件
with open('data.pkl', 'wb') as f:
pickle.dump((x_train, y_train), f)
# 断言x与y个数相等,打乱
assert len(x) == len(y)
p = np.random.permutation(range(len(x)))
x, y = x[p], y[p]