TensorFlow- tf.argmax 函数学习

tf.argmax 格式

tf.argmax
argmax(
input,
axis=None,
name=None,
dimension=None
)
其中,input为一个张量,类型为 float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half
axis 表示选取的坐标轴
name 为该操作取名

看一个栗子

import tensorflow as tf
import numpy as np
ipt = np.array([[1,2,1,4],[10,3,2,8],[6,7,9,66],[5,45,78,54]])
res = tf.argmax(ipt,0)
sess = tf.Session()
opt = sess.run(res)
print(opt)

输出结果为:
[1 3 3 2]

输出结果解释

首先,argmax返回的是索引值,返回每一行或者每一列的最大值的索引,当选择axis=1时。表示每一行的最大值,0表示每列的最大值索引,看上面的例子,第一列最大值为10,为该列的第二个,所以索引为1,第二列,最大值为45。为第四个,所以索引为3,第三列最大值为78,为第四个,索引为3,最后一个最大值为66,为第三个,所以索引为2。

axis 换成1

import tensorflow as tf
import numpy as np
ipt = np.array([[1,2,1,4],[10,3,2,8],[6,7,9,66],[5,45,78,54]])
res = tf.argmax(ipt,1)
sess = tf.Session()
opt = sess.run(res)
print(opt)

[3 0 3 2]
当axis为1,就是比每一行的值,返回最大值在该行的索引,比如,第一行,最大值为4,为第四个,索引为3,第二行最大值为10,为第一个,索引为0,以此类推。

tf.argmin

和argmax格式之类的都是一样,但是返回的是最小值对应的索引

其实tensorflow中的argmin,argmax和numpy中的argmin,argmax是一样的,都是返回索引

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值