tensor 维度 问题。
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 维度 问题。的更多相关文章
- [TensorFlow]Tensor维度理解
http://wossoneri.github.io/2017/11/15/[Tensorflow]The-dimension-of-Tensor/ Tensor维度理解 Tensor在Tensorf ...
- pytorch 中改变tensor维度的几种操作
具体示例如下,注意观察维度的变化 #coding=utf-8 import torch """改变tensor的形状的四种不同变化形式""" ...
- tensorflow中的函数获取Tensor维度的两种方法:
获取Tensor维度的两种方法: Tensor.get_shape() 返回TensorShape对象, 如果需要确定的数值而把TensorShape当作list使用,肯定是不行的. 需要调用Tens ...
- tensor维度变换
维度变换是tensorflow中的重要模块之一,前面mnist实战模块我们使用了图片数据的压平操作,它就是维度变换的应用之一. 在详解维度变换的方法之前,这里先介绍一下View(视图)的概念.所谓Vi ...
- Pytorch Tensor 维度的扩充和压缩
维度扩展 x.unsqueeze(n) 在 n 号位置添加一个维度 例子: import torch x = torch.rand(3,2) x1 = x.unsqueeze(0) # 在第一维的位置 ...
- pytorch tensor 维度理解.md
torch.randn torch.randn(*sizes, out=None) → Tensor(张量) 返回一个张量,包含了从标准正态分布(均值为0,方差为 1)中抽取一组随机数,形状由可变参数 ...
- tensor的维度扩张的手段--Broadcasting
broadcasting是tensorflow中tensor维度扩张的最常用的手段,指对某一个维度上重复N多次,虽然它呈现数据已被扩张,但不会复制数据. 可以这样理解,对 [b,784]@[784,1 ...
- 05_pytorch的Tensor操作
05_pytorch的Tensor操作 目录 一.引言 二.tensor的基础操作 2.1 创建tensor 2.2 常用tensor操作 2.2.1 调整tensor的形状 2.2.2 添加或压缩t ...
- Tensor基本理论
Tensor基本理论 深度学习框架使用Tensor来表示数据,在神经网络中传递的数据均为Tensor. Tensor可以将其理解为多维数组,其可以具有任意多的维度,不同Tensor可以有不同的数据类型 ...
随机推荐
- Windows 系统定时自动重启
1.创建新文本并输入 shutdown -r -t 0 保存成.bat文件 2.创建系统任务计划 2.1 在开始中打开[任务计划程序] 2.2 新建创建任务计划目录 2.3 在新目录下新建任务计划即可 ...
- LeetCode 366. Find Leaves of Binary Tree
原题链接在这里:https://leetcode.com/problems/find-leaves-of-binary-tree/#/description 题目: Given a binary tr ...
- (转)移动端开发总结(一)视口viewport总结
转载链接:移动端开发中,关于适配问题的一点总结(一) 视口 布局视口layout viewport 视觉视口visual viewport 理想视口 缩放 一个重大区别 最小缩放 和最大缩放 分辨率 ...
- sqlalchemy的缓存和刷新
其实只是第一次查询了数据库,其他的时候都使用的是缓存,所以有时候,因为这个特性会出错,所以需要刷新对象或者使对象过期 参考链接:http://www.cnblogs.com/fengyc/p/5369 ...
- Oracle的闪回特性之恢复truncate删除表的数据
Oracle的闪回特性之恢复truncate删除表的数据 SQL> show parameter flashback NAME T ...
- Ununto16.04版本Docker的安装2018年最新版本
最近参照网上教程安装ubuntu的Docker怎么都不成功,我最后参照官方文档成功安装 https://docs.docker.com/engine/installation/linux/docker ...
- memcache使用经历
memcache可以看成是一个大内存库,因为可以集群,所以可以看成是无限大的内存库.既然是内存库,那么我们放的就是一些map了.map里就键值对,虽然内存可以通过集群的方式无限扩展,但单个键值对的大小 ...
- 从jvm角度来解析java语法糖
java有很多语法糖,比如自动拆箱,自动装箱,foreach等等,这些原理相信每一个入门教程里都有讲,但是我相信不是每一个人 都通过查看这些语法糖的字节码来确认这些原理,因为我也是现在才想看一下. 1 ...
- UDP协议相关解释
UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联) 参考模型中一种无连接的传输层 ...
- VisualGDB:使用VS创建CMake Linux项目
转载地址:点击打开链接 根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何使用 ...