tf.argmax takes two arguments: input and dimension. example: tf.argmx(arr, dimension = 1). or tf.argmax(arr, 1). let arr is ndarray

wrong: Since the indices of array arr are arr[rows, columns], I would expect tf.argmax(arr, 0) to return the index of the maximum element per row, while I would have expected tf.argmax(arr, 1) to return the maximum element per column. Likewise for tf.argmin.

right understand:

Think of the dimension argument of tf.argmax as the axis across which you reduce.

tf.argmax(arr, 0) reduces across dimension 0, i.e. the rows. Reducing across rows means that you will get the argmax of each individual column.

把tf.argmax变量中的dimension理解为你需要通过轴x来降解维度。 tf.argmax(arr, 0)意味着: 穿过axis=0 (即横轴row), 穿过row(行)来降解。 而穿过行来讲解,也就是你要对每一列来进行操作。 

This might be counterintuitive, but it falls in line with the conventions used in tf.reduce_max and so on.

Additionally: how does this behave for n-dimensional Tensors? I'm a bit lost at figuring out which dimension relates to reducing i, j, k, l or m in a 5D-Tensor. – daniel451 Jun 29 '16 at 9:12

By definition, if you search for the maximum across rows, you are searching within columns.

For any d-dimensional array, taking the argmax across the ith axis means that, for any possible combination of the d-1 remaining indices, you are searching for the maximum amongst arr[ind1, ind2, ..., ind_i_minus_1, : , ind_i_plus_1, ..., ind_d]  ==》还是对列进行操作, zhi

下例中 X 定义了有784维的tf 占位符。行数没有定义 。

Y 定义了有10维的tf 占位符。行数也没有定义 。

X = tf.placeholder("float", [None, 784]) # create symbolic variables
Y = tf.placeholder("float", [None, 10]) w = init_weights([784, 10]) # like in linear regression, we need a shared variable weight matrix for logistic regression py_x = model(X, w)。# 可以看出py_x 同Y一样是一个有10维的tf占位符。 也就是说有10个标签,10列构成的一个行向量。 行数根据可feed情况推断。 cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, Y)) # compute mean cross entropy (softmax is applied internally)
train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # construct optimizer
predict_op = tf.argmax(py_x, 1) # at predict time, evaluate the argmax of the logistic regression # dimension =1,就是穿过列,对整行进行取最大值对应的行好。 如果不理解,往下看:

 

import tensorflow as tf
mygraph = tf.Graph()
with tf.Session() as sess:
x = tf.constant([1,2,3])
y = tf.constant([3,4,5])

op = tf.add(x,y)
result = sess.run(fetches = op)
print result

x = tf.constant([[1,220,55],[4,3,-1]])
with tf.Session() as sess:
result = tf.argmax(x,1) # 输出变量的索引
print sess.run(result) # output: [1 0]
x = tf.constant([[1, 220, 55], [4, 3, -1]])
x_max = tf.reduce_max(x, reduction_indices=[1])
print sess.run(x_max) # ==> "array([220, 4], dtype=int32)"

tensor 维度 问题。的更多相关文章

  1. [TensorFlow]Tensor维度理解

    http://wossoneri.github.io/2017/11/15/[Tensorflow]The-dimension-of-Tensor/ Tensor维度理解 Tensor在Tensorf ...

  2. pytorch 中改变tensor维度的几种操作

    具体示例如下,注意观察维度的变化 #coding=utf-8 import torch """改变tensor的形状的四种不同变化形式""" ...

  3. tensorflow中的函数获取Tensor维度的两种方法:

    获取Tensor维度的两种方法: Tensor.get_shape() 返回TensorShape对象, 如果需要确定的数值而把TensorShape当作list使用,肯定是不行的. 需要调用Tens ...

  4. tensor维度变换

    维度变换是tensorflow中的重要模块之一,前面mnist实战模块我们使用了图片数据的压平操作,它就是维度变换的应用之一. 在详解维度变换的方法之前,这里先介绍一下View(视图)的概念.所谓Vi ...

  5. Pytorch Tensor 维度的扩充和压缩

    维度扩展 x.unsqueeze(n) 在 n 号位置添加一个维度 例子: import torch x = torch.rand(3,2) x1 = x.unsqueeze(0) # 在第一维的位置 ...

  6. pytorch tensor 维度理解.md

    torch.randn torch.randn(*sizes, out=None) → Tensor(张量) 返回一个张量,包含了从标准正态分布(均值为0,方差为 1)中抽取一组随机数,形状由可变参数 ...

  7. tensor的维度扩张的手段--Broadcasting

    broadcasting是tensorflow中tensor维度扩张的最常用的手段,指对某一个维度上重复N多次,虽然它呈现数据已被扩张,但不会复制数据. 可以这样理解,对 [b,784]@[784,1 ...

  8. 05_pytorch的Tensor操作

    05_pytorch的Tensor操作 目录 一.引言 二.tensor的基础操作 2.1 创建tensor 2.2 常用tensor操作 2.2.1 调整tensor的形状 2.2.2 添加或压缩t ...

  9. Tensor基本理论

    Tensor基本理论 深度学习框架使用Tensor来表示数据,在神经网络中传递的数据均为Tensor. Tensor可以将其理解为多维数组,其可以具有任意多的维度,不同Tensor可以有不同的数据类型 ...

随机推荐

  1. 解决Chrome关联HTML文件,图标不显示的问题。

    解决Chrome关联HTML文件,图标不显示的问题. 一.方法一 1.win+r,输入regedit,调出注册表信息,按下Ctrl+F,在注册表里搜索.在注册表里新建几个文件就可以了 a.新建Old ...

  2. 重温CLR(八 ) 泛型

    熟悉面向对象编程的开发人员都深谙面向对象的好处,其中一个好处是代码重用,它极大提高了开发效率.也就是说,可以派生出一个类,让他继承基类的所有能力.派生类只需要重写虚方法,或添加一些新方法,就可定制派生 ...

  3. WCF+上传+大文件处理

    大文件处理的方式拆分读取,此文只为记录文件处理方式,供日后查阅. 源码来自http://blog.csdn.net/lywust/article/details/7009248 经过改编将源码改编为文 ...

  4. 转载pll工作模式解析

    PLL共有四种工作模式,只有理解了这四种工作模式的特点,才能在设计中选用恰当的模式,完成自己设计的预期功能.这四种工作模式分别是普通模式(Normal Mode).零延迟缓冲模式(Zero Delay ...

  5. 前端工程师面试问题归纳(一、问答类html/css/js基础)

    一.参考资源 1.前端面试题及答案整理(一) 2.2017年前端面试题整理汇总100题 3.2018最新Web前端经典面试试题及答案 4.[javascript常见面试题]常见前端面试题及答案 5.W ...

  6. jquery移除、绑定、触发元素事件

    unbind(type [,data]) //data是要移除的函数 $('#btn').unbind("click"); //移除click $('#btn').unbind() ...

  7. unity drawcall测试

    unity引擎影响drawcall的元素(使用Quad和Cube对比测试) 1.相机的background(没有渲染元素区域的颜色),4Verts.2Tris.1SetPass calls:      ...

  8. IE 9 下的 css 陷阱

    IE 9 下的 css 陷阱 今天 Karson 老大的分享. 根据说明 当 css 文件超过一定大小时会被自动截断. http://ju.outofmemory.cn/entry/168599

  9. hdu 3625 Examining the Rooms——第一类斯特林数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 n^2 求斯特林数就行.要减去的就是1号钥匙在1号房间的方案,即 s[ n-1 ][ m-1] . ...

  10. 洛谷 1514 (NOIp2010) 引水入城

    题目:https://www.luogu.org/problemnew/show/P1514 如果有解,一个第一行的格子能覆盖第n行的一定是一个连续的区间. 因为如果不连续,则有围住了一些第n行的格子 ...