tf.argmax 与 tf.arg_max

tf.argmax 与 tf.arg_max 用法相同,下面介绍 tf.argmax 用法

tf.argmax

def argmax(input,
           axis=None,
           name=None,
           dimension=None,
           output_type=dtypes.int64)
numpy.argmax(a, axis=None, out=None) 
返回沿轴axis最大值的索引。

Parameters: 
input: array_like,数组
axis : int, 可选,默认情况下,索引的是平铺的数组,否则沿指定的轴。 
out : array, 可选 如果提供,结果以合适的形状和类型被插入到此数组中。 

Returns: 
index_array : ndarray of ints 
索引数组。它具有与a.shape相同的形状,其中axis被移除。          

tf.argmax() 与 numpy.argmax() 方法的用法是一致的

axis = 0 的时候返回每一列最大值的位置索引
axis = 1 的时候返回每一行最大值的位置索引
axis = 2、3、4 ...,即为多维张量时,同理推断

例子

>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)  #0代表列
array([1, 1, 1])
>>> np.argmax(a, axis=1)  #1代表行
array([2, 2])
>>>
>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> np.argmax(b)  #只返回第一次出现的最大值的索引
1

tf.arg_max()

The following is the source code of argmax (from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/math_ops.py).

# pylint: disable=redefined-builtin
# TODO(aselle): deprecate arg_max
def argmax(input, axis=None, name=None, dimension=None):
  if dimension is not None:
    if axis is not None:
      raise ValueError("Cannot specify both 'axis' and 'dimension'")
    axis = dimension
  elif axis is None:
    axis = 0
  return gen_math_ops.arg_max(input, axis, name)

As you can see, argmax is using arg_max inside. Also from the code, I recommend using argmax because arg_max could be deprecated soon.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值