转载请注明出处:http://www.cnblogs.com/willnote/p/6758953.html

官方API定义

tf.argmax(input, axis=None, name=None, dimension=None)

Returns the index with the largest value across axes of a tensor.

Args:

  • input: A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half.
  • axis: A Tensor. Must be one of the following types: int32, int64. int32, 0 <= axis < rank(input). Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0.
  • name: A name for the operation (optional).

Returns:

  • A Tensor of type int64.

关于axis

定义中的axis与numpy中的axis是一致的,下面通过代码进行解释

import numpy as np
import tensorflow as tf sess = tf.session()
m = sess.run(tf.truncated_normal((5,10), stddev = 0.1) )
print type(m)
print m -------------------------------------------------------------------------------
<type 'numpy.ndarray'>
[[ 0.09957541 -0.0965599 0.06064715 -0.03011306 0.05533558 0.17263047
-0.02660419 0.08313394 -0.07225946 0.04916157]
[ 0.11304571 0.02099175 0.03591062 0.01287777 -0.11302195 0.04822164
-0.06853487 0.0800944 -0.1155676 -0.01168544]
[ 0.15760773 0.05613248 0.04839646 -0.0218203 0.02233066 0.00929849
-0.0942843 -0.05943 0.08726917 -0.059653 ]
[ 0.02553608 0.07298559 -0.06958302 0.02948747 0.00232073 0.11875584
-0.08325859 -0.06616175 0.15124641 0.09522969]
[-0.04616683 0.01816062 -0.10866459 -0.12478453 0.01195056 0.0580056
-0.08500613 0.00635608 -0.00108647 0.12054099]]

m是一个5行10列的矩阵,类型为numpy.ndarray

#使用tensorflow中的tf.argmax()
col_max = sess.run(tf.argmax(m, 0) ) #当axis=0时返回每一列的最大值的位置索引
print col_max row_max = sess.run(tf.argmax(m, 1) ) #当axis=1时返回每一行中的最大值的位置索引
print row_max array([2, 3, 0, 3, 0, 0, 0, 0, 3, 4])
array([5, 0, 0, 8, 9]) -------------------------------------------------------------------------------
#使用numpy中的numpy.argmax
row_max = m.argmax(0)
print row_max col_max = m.argmax(1)
print col_max array([2, 3, 0, 3, 0, 0, 0, 0, 3, 4])
array([5, 0, 0, 8, 9])

可以看到tf.argmax()与numpy.argmax()方法的用法是一致的

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

参考

  1. Tensorflow官方API tf.argmax说明
  2. Numpy官方AIP numpy.argmax说明

Tensorflow中的tf.argmax()函数的更多相关文章

  1. TensorFlow中的L2正则化函数:tf.nn.l2_loss()与tf.contrib.layers.l2_regularizerd()的用法与异同

    tf.nn.l2_loss()与tf.contrib.layers.l2_regularizerd()都是TensorFlow中的L2正则化函数,tf.contrib.layers.l2_regula ...

  2. tf.argmax()函数作用

    tf.argmax()函数原型: def argmax(input, axis=None, name=None, dimension=None, output_type=dtypes.int64) 作 ...

  3. tensorflow中使用tf.variable_scope和tf.get_variable的ValueError

    ValueError: Variable conv1/weights1 already exists, disallowed. Did you mean to set reuse=True in Va ...

  4. tf.Session()函数的参数应用(tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dcrmg/article/details ...

  5. 【Tensorflow】tf.argmax函数

    tf.argmax(input, axis=None, name=None, dimension=None) 此函数是对矩阵按行或列计算最大值   参数 input:输入Tensor axis:0表示 ...

  6. [转载]tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定

    tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...

  7. TensorFlow 中的 tf.train.exponential_decay() 指数衰减法

    exponential_decay(learning_rate, global_step, decay_steps, decay_rate, staircase=False, name=None) 使 ...

  8. tensorflow中共享变量 tf.get_variable 和命名空间 tf.variable_scope

    tensorflow中有很多需要变量共享的场合,比如在多个GPU上训练网络时网络参数和训练数据就需要共享. tf通过 tf.get_variable() 可以建立或者获取一个共享的变量. tf.get ...

  9. tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定

    tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...

随机推荐

  1. 递归C++

    递归C++ 一.递归简介 自己调用自己 二.递归写法 2.1 写法介绍 先写出问题的递推公式 递归部分的边界条件就是递推公式中的边界条件 递归部分的主体部分就是递推公式中的主体部分 2.2 实例 (1 ...

  2. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 问题解决方法

    在用maven配置mybatis环境时出现此BindingExceptiony异常,发现在classes文件下没有mapper配置文件,应该是maven项目没有扫描到mapper包下的xml文件,在p ...

  3. 缓存地图 ArcGIS ——Local compact and exploded tile cache layer for WPF API

      ArcGISArcGIS 主页 特色 合约 图库 地图 组 帮助 我的内容 我的组织 登录 我的个人资料 帮助 管理员指南 登出 0 搜索全部内容 搜索地图 搜索图层 搜索应用程序 搜索工具 搜索 ...

  4. English trip -- VC(情景课) 8 A Get ready

    Words cashier  # 收银员                a cashier counts money   收钱 custodian  # 清洁工     a custodian  cl ...

  5. 20170714xlVba多个工作簿转多个Word文档表格

    Public Sub SameFolderGather() Application.ScreenUpdating = False Application.DisplayAlerts = False A ...

  6. Vue.js Cookbook: 添加实例属性; 👍 axios(4万➕✨)访问API; filters过滤器;

    add instance properties //加上$,防止和已经定义的data,method, computed的名字重复,导致被覆写.//可以自定义添加其他符号. Vue.prototype. ...

  7. Vue组件(知识)

    form最后一节. 组件基础 组件的复用:  data必须是函数 组织 通过Prop向子组件传递data 单个根元素 通过event向父组件发送消息: 使用事件抛出一个value, 在组件上用v-mo ...

  8. ccfZ字形扫描

    问题描述 在图像编码的算法中,需要将一个给定的方形矩阵进行Z字形扫描(Zigzag Scan).给定一个n×n的矩阵,Z字形扫描的过程如下图所示: 对于下面的4×4的矩阵, 1 5 3 9 3 7 5 ...

  9. Py打包exe报错

      Py打包exe报错       下载地址 https://github.com/pyinstaller/pyinstaller       用管理员执行   pip install https:/ ...

  10. CAS-认证流程

    从结构上看cas包括两个部分,CAS server 和CAS client 需要独立部署,主要负责用户的认证工作,CAS负责处理对客户端受保护资源的访问请求,需要登录时,重新定向到CAS Server ...