tf.concat( )和tf.stack( )
相同点:都是组合重构数据.
不同点:concat()不改变维数,而stack改变了维数(待定!!!)
tf.concat是连接两个矩阵的操作,请注意API版本更改问题,相应参数也发生改变,具体查看API.
tf.concat(concat_dim, values, name='concat')
除去name参数用以指定该操作的name,与方法有关的一共两个参数:
第一个参数concat_dim:必须是一个数,表明在哪一维上连接
如果concat_dim是0,那么在某一个shape的第一个维度上连,对应到实际,就是叠放到列上
- t1 = [[1, 2, 3], [4, 5, 6]]
- t2 = [[7, 8, 9], [10, 11, 12]]
- tf.concat(0, [t1, t2]) == > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat(0, [t1, t2]) == > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
如果concat_dim是1,那么在某一个shape的第二个维度上连
- t1 = [[1, 2, 3], [4, 5, 6]]
- t2 = [[7, 8, 9], [10, 11, 12]]
- tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12
如果有更高维,最后连接的依然是指定那个维:
values[i].shape = [D0, D1, ... Dconcat_dim(i), ...Dn]连接后就是:[D0, D1, ... Rconcat_dim, ...Dn]
- # tensor t3 with shape [2, 3]
- # tensor t4 with shape [2, 3]
- tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3]
- tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6]
# tensor t3 with shape [2, 3]
# tensor t4 with shape [2, 3]
tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3]
tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6]
第二个参数values:就是两个或者一组待连接的tensor了
/×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××/
这里要注意的是:如果是两个向量,它们是无法调用
- tf.concat(1, [t1, t2])
tf.concat(1, [t1, t2])
来连接的,因为它们对应的shape只有一个维度,当然不能在第二维上连了,虽然实际中两个向量可以在行上连,但是放在程序里是会报错的
如果要连,必须要调用tf.expand_dims来扩维:
- t1=tf.constant([1,2,3])
- t2=tf.constant([4,5,6])
- #concated = tf.concat(1, [t1,t2])这样会报错
- t1=tf.expand_dims(tf.constant([1,2,3]),1)
- t2=tf.expand_dims(tf.constant([4,5,6]),1)
- concated = tf.concat(1, [t1,t2])#这样就是正确的
tf.concat( )和tf.stack( )的更多相关文章
- tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask
1. tf.split(3, group, input) # 拆分函数 3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值 import tensorflow ...
- tf.concat()
转载自:https://blog.csdn.net/appleml/article/details/71023039 https://www.cnblogs.com/mdumpling/p/80534 ...
- tensorflow 生成随机数 tf.random_normal 和 tf.random_uniform 和 tf.truncated_normal 和 tf.random_shuffle
____tz_zs tf.random_normal 从正态分布中输出随机值. . <span style="font-size:16px;">random_norma ...
- tf.concat, tf.stack和tf.unstack的用法
tf.concat, tf.stack和tf.unstack的用法 tf.concat相当于numpy中的np.concatenate函数,用于将两个张量在某一个维度(axis)合并起来,例如: a ...
- 深度学习原理与框架-Alexnet(迁移学习代码) 1.sys.argv[1:](控制台输入的参数获取第二个参数开始) 2.tf.split(对数据进行切分操作) 3.tf.concat(对数据进行合并操作) 4.tf.variable_scope(指定w的使用范围) 5.tf.get_variable(构造和获得参数) 6.np.load(加载.npy文件)
1. sys.argv[1:] # 在控制台进行参数的输入时,只使用第二个参数以后的数据 参数说明:控制台的输入:python test.py what, 使用sys.argv[1:],那么将获得w ...
- tensorflow报错error,tf.concat Expected int32, got list containing Tensors of type '_Message' instead
参考:https://stackoverflow.com/questions/41813665/tensorflow-slim-typeerror-expected-int32-got-list-co ...
- tensorflow 笔记7:tf.concat 和 ops中的array_ops.concat
用于连接两个矩阵: mn = array_ops.concat([a, d], 1) # 按照第二维度相接,shape1 [m,a] shape2 [m,b] ,concat_done shape ...
- 学习TensorFlow的tf.concat使用
https://www.tensorflow.org/api_docs/python/tf/concat
- tf.concat的用法
import numpy as npimport tensorflow as tfsess=tf.Session()a=np.zeros((1,2,3,4))b=np.ones((1,2,3,4))c ...
随机推荐
- Redis 5.0
1.概述默认端口号:6379 redis是一种nosql数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,并且他比memcached支持更多的数据结构(s ...
- 【FICO系列】SAP 参数(条件表)灵活配置GS01/GS02/GS03
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP 参数(条件表)灵活配 ...
- LeetCode.914-一副牌中的X(X of a Kind in a Deck of Cards)
这是悦乐书的第352次更新,第377篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第214题(顺位题号是914).在一副牌中,每张牌上都写有一个整数. 当且仅当您可以选择 ...
- MySQL各种函数/语法
@limit pos,len select * from table limit 5,10 只显示查出结果的6-15行 ---------------------------------------- ...
- shell下的 awk/sed/grep/seq/tr
转自:实例手册 https://github.com/liquanzhou/ops_doc/blob/master/shell%E5%AE%9E%E4%BE%8B%E6%89%8B%E5%86%8C. ...
- 小记---------网页采集之selenium
1.元素定位 ID定位元素: findElement(By.id(“”)); 通过元素的名称定位元素: findElement(By.name(“”)); 通过元素的html中的位置定位元素 ...
- oracle group by rollup实现小计、合计
SQL合计汇总实现数据N+1条显示: 注意group by rollup((ename, job, empno))!!! select decode(grouping(ename) + groupin ...
- awk对文件的奇偶行做处理
{ if(NR % 2 == 0) printf("%s\n", $0) else printf("%s, ", $1) } awk -f awk.awk da ...
- IDEA Maven项目 pom.xml 找不到 Dependency 依赖
转载: IDEA Maven项目 pom.xml 找不到 Dependency 依赖 如果你的pom.xml中使用了dependencyManagement管理依赖并且添加了你本地仓库中不存在的依赖可 ...
- 2017年0406------如何使用sessionStroage来储存参数是对象的,以及localStorage和sessionStorage的不同地方
由于项目需要,需要向另外个页面传参数,,由于参数比较特殊,是对象,所以需要用到sessionStorage方法,下面简单的总结一下方法: (1)这个是要将对象转换成字符串,再存储到storage中, ...