1,显示一下mnist数据中的图片看看
#coding=utf-8
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import numpy as np
mnist = input_data.read_data_sets("/tmp/data",one_hot=True)
#将图片转换为28*28的
test_image= mnist.test.images[0].reshape((28,28))
#图像类型原来为浮点型,转换为整型
test_image = (test_image*255).astype(int)
print(test_image)
plt.figure(1)
#绘制灰度图像
plt.imshow(test_image,cmap ='gray')
# plt.imshow(test_image,cmap =plt.cm.gray)
#plt.imshow(test_image,cmap =plt.cm.gray_r)#图像黑白翻转
plt.show()

2.tf.argmax()
tf.argmax(input, axis=None, name=None, dimension=None)
返回最大值的索引号
import tensorflow as tf
import numpy as np
A = [[1,3,4,5,6]]
B = [[1,3,4], [2,4,1]]
with tf.Session() as sess:
print(sess.run(tf.argmax(A, 1)))#4
print(sess.run(tf.argmax(B, 1)))#[2,1]
axis:0表示列,1表示行,别搞那么复杂,能跑就行
test = np.array([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2]])
np.argmax(test, 0)#输出:array([3, 3, 1]
np.argmax(test, 1)#输出:array([2, 2, 0, 0]
注意:input的类型不能是(4,)这样的,会报错
a = [1,2,3,4]
sess.run(tf.argmax(a,1))会报错
a得是[[1,2,3,4]]这样的
3.格式化输出列表
好像输出列表的时候不能使用%d,要么直接输出,要么使用format