Tensorflow中的tf.argmax()函数
转载请注明出处: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...,即为多维张量时,同理推断
参考
Tensorflow中的tf.argmax()函数的更多相关文章
- 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 ...
- tf.argmax()函数作用
tf.argmax()函数原型: def argmax(input, axis=None, name=None, dimension=None, output_type=dtypes.int64) 作 ...
- tensorflow中使用tf.variable_scope和tf.get_variable的ValueError
ValueError: Variable conv1/weights1 already exists, disallowed. Did you mean to set reuse=True in Va ...
- tf.Session()函数的参数应用(tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dcrmg/article/details ...
- 【Tensorflow】tf.argmax函数
tf.argmax(input, axis=None, name=None, dimension=None) 此函数是对矩阵按行或列计算最大值 参数 input:输入Tensor axis:0表示 ...
- [转载]tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定
tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...
- TensorFlow 中的 tf.train.exponential_decay() 指数衰减法
exponential_decay(learning_rate, global_step, decay_steps, decay_rate, staircase=False, name=None) 使 ...
- tensorflow中共享变量 tf.get_variable 和命名空间 tf.variable_scope
tensorflow中有很多需要变量共享的场合,比如在多个GPU上训练网络时网络参数和训练数据就需要共享. tf通过 tf.get_variable() 可以建立或者获取一个共享的变量. tf.get ...
- tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定
tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True ...
随机推荐
- 手动添加 launcher 到 Ubuntu Unity
本来,启动程序之后,在左边的launcher bar点右键,[Lock to Launcher]就可以的. 但是,有时候因为某种原因,需要手工添加. 这时候,就要参考下面的文章了 http://ask ...
- HDU-3729 二分匹配 匈牙利算法
题目大意:学生给出其成绩区间,但可能出现矛盾情况,找出合理组合使没有说谎的人尽可能多,并按maximum lexicographic规则输出组合. //用学生去和成绩匹配,成绩区间就是学生可以匹配的成 ...
- Android之ToolBar和自定义ToolBar实现沉浸式状态栏
沉浸式状态栏确切的说应该叫做透明状态栏.一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明. 沉浸式状态栏是从android Kitkat(Android 4.4)开始出 ...
- 使用Laravel提交POST请求出现The page has expired due to inactivity错误
任何指向 web 中 POST, PUT 或 DELETE 路由的 HTML 表单请求都应该包含一个 CSRF 令牌(CSRF token),否则,这个请求将会被拒绝.
- 『PyTorch』第一弹_静动态图构建if逻辑对比
对比TensorFlow和Pytorch的动静态图构建上的差异 静态图框架设计好了不能够修改,且定义静态图时需要使用新的特殊语法,这也意味着图设定时无法使用if.while.for-loop等结构,而 ...
- ubuntu64位库
安装 12.04ubuntu32位库:sudo apt-get install ia32-libs
- Mysql查询用逗号分隔的字段-字符串函数FIND_IN_SET(),以及此函数与in()函数的区别
查询用逗号分隔的字段,可以用字符串函数FIND_IN_SET(): 查询数据库表中某个字段(值分行显示),可以用函数in(). 今天工作中遇到一个问题,就是用FIND_IN_SET()函数解决的. 第 ...
- js 正则去除指定的单词
以企业邮箱为例:@后面不能是qq 126 163 188 gmail yahoo sina hotmail suhu sogu 等单词. <!DOCTYPE htm ...
- jenkins插件--Cobertura,JaCoCo,Emma-----(二)
代码覆盖API插件 Jenkins中有许多代码覆盖插件:Cobertura,JaCoCo,Emma等等.这些插件的问题在于它们每个都自己实现了所有代码覆盖功能.因此,您可以获得不同的功能集,UI,CL ...
- 快速切题 poj3026
感受到出题人深深的~恶意 这提醒人们以后...数字后面要用gets~不要getchar 此外..不要相信那个100? Borg Maze Time Limit: 1000MS Memory Lim ...