tensorflow tf.argmax() 用法 例子

argmax()官方文档如下:

tf.argmax(input, dimension, name=None) 
Returns the index with the largest value across dimensions of a tensor. 
Args: 
input: A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, int16, int8, complex64, qint8, quint8, qint32. 
dimension: A Tensor of type int32. int32, 0 <= dimension < rank(input). Describes which dimension of the input Tensor to reduce across. For vectors, use dimension = 0. 
name: A name for the operation (optional). 
Returns: 
A Tensor of type int64.

 

dimension=0 按列找 
dimension=1 按行找 
tf.argmax()返回最大数值的下标 
通常和tf.equal()一起使用,计算模型准确度

correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
import numpy as np
x = np.array([1, 2])
y = np.array([[1],[2]])
print x.shape
print y.shape
>>>
(2,)
(2, 1)

[1,2]的shape值(2,),意思是一维数组,数组中有2个元素。

[[1],[2]]的shape值是(2,1),意思是一个二维数组,每行有1个元素。

[[1,2]]的shape值是(1,2),意思是一个二维数组,每行有2个元素。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值