tf.argmax(
input,
axis=None,
name=None,
dimension=None,
output_type=tf.int64
)
Returns the index with the largest value across axes of a tensor. (deprecated arguments)
返回张量轴上最大值的索引。
SOME ARGUMENTS ARE DEPRECATED.
They will be removed in a future version.
Instructions for updating: Use the axis argument instead
更新说明:使用axis参数
Note that in case of ties the identity of the return value is not guaranteed.
注意,在绑定的情况下,返回值的标识不能保证。
此函数是对矩阵按行或列计算最大值
参数
input:输入Tensor
axis:0表示按列,1表示按行
name:名称
dimension:和axis功能一样,默认axis取值优先。新加的字段
返回:Tensor 一般是行或列的最大值下标向量
import tensorflow as tf
初始化一个三行四列矩阵,填入从均匀分布中输出0-10之间的随机值。
ranMatrix = tf.Variable(tf.random_uniform([3,4],minval=0,maxval=10))
分别求出矩阵中 列最大值的索引 和 行最大值的索引
MaxColumn = tf.argmax(input = ranMatrix,axis = 0)
MaxLine = tf.argmax(input = ranMatrix,axis = 1)
初始化所有变量
sess = tf.Session()
sess.run(tf.initialize_all_variables())
输出矩阵
print(sess.run(ranMatrix))
[[ 1.61229014 4.98661518 3.85476351 4.64553595]
[ 3.45184088 4.1815958 7.58010149 8.12338257]
[ 6.54159784 1.9306457 4.3276763 3.04282904]]
列最大值的索引
print(sess.run(MaxColumn))
[2 0 1 1]
行最大值的索引
print(sess.run(MaxLine))
[1 3 0]
网友评论