tf.argmax()函数介绍和示例

tf.argmax()函数介绍和示例
tf.argmax(input_tensor, axis=0)

释义:返回指定维度最大值的索引

  • input_tensor,输入张量

  • axis,指定维度,默认为0。二维情况下,若为0,则返回列数据最大值索引;若为1,则返回行数据最大值索引

示例

import tensorflow as tf

X = tf.constant([[1, 2, 3], 
                 [2, 3, 4], 
                 [5, 4, 3], 
                 [8, 7, 2]], dtype=tf.float32)
row_max_index = tf.argmax(X)               # 默认 0 维度,列最大值索引
col_max_index = tf.argmax(X, axis=1)       # axis=1 或 1,行最大值索引

with tf.Session() as sess:
    print('列最大值索引:', sess.run(row_max_index))
    print('行最大值索引:', sess.run(col_max_index))
列最大值索引: [3 3 1]
行最大值索引: [2 2 0 0]
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值