tensorflow教程1

1、tf.argmax()使用方法

tf.argmax(A,1):第二个参数为1时返回矩阵中每一行最大值的索引号

import tensorflow as tf

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)))
    print(sess.run(tf.argmax(B, 1)))

返回:

[4]

[2 1]

tf.argmax(A,0):第二个参数为0时返回矩阵中每一列最大值的索引号

import tensorflow as tf

A = [[1, 3, 4, 5, 6]]
B = [[1, 3, 4], [2, 4, 1]]

with tf.Session() as sess:
    print(sess.run(tf.argmax(A, 0)))
    print(sess.run(tf.argmax(B, 0)))

返回:

[0 0 0 0 0]

[1 1 0]

tf.reduce_mean()函数使用教程

# 'x' is [[1., 2.]
#         [3., 4.]]

tf.reduce_mean(x) ==> 2.5 #如果不指定第二个参数,那么就在所有的元素中取平均值
tf.reduce_mean(x, 0) ==> [2.,  3.] #指定第二个参数为0,则第一维的元素取平均值,即每一列求平均值
tf.reduce_mean(x, 1) ==> [1.5,  3.5] #
# 指定第二个参数为1,则第二维的元素取平均值,即每一行求平均值


猜你喜欢

转载自blog.csdn.net/ti09257/article/details/80612190