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 ...
随机推荐
- java游戏服务器 策略+简单工厂
上一篇中我们讲到简单工厂模式有它的弊端,它不好在哪里呢? 我们看到,每次创建场景,我们都需要暴露两个类... 这是比较不好的, 可以通过策略模式+简单工厂模式来稍微改造下 一.先来一个策略模式UML图 ...
- python--006
一.函数的作用域 1.作用域在定义函数时就已经固定住了,不会随着调用位置的改变而改变 例一: name='alex' def foo(): name='lhf' def bar(): print(na ...
- python学习之网络基础
七 网络编程 7.1 C/S B/S架构 7.1.1 认识 Client : 客户端 Browser :浏览器 Server :服务器端 C/S:客户端与服务器之间的构架 B/S:浏览器与服务器之间的 ...
- Linux下用Java获取本机IP
可能有多个网卡包括虚拟网卡,需要进行排除 String ip = ""; try { Enumeration<?> e1 = NetworkInterface.getN ...
- Python xlsxwriter库 图表Demo
折线图 import xlsxwriter # 创建一个excel workbook = xlsxwriter.Workbook("chart_line.xlsx") # 创建一个 ...
- Akka系列(四):Akka中的共享内存模型
前言...... 通过前几篇的学习,相信大家对Akka应该有所了解了,都说解决并发哪家强,JVM上面找Akka,那么Akka到底在解决并发问题上帮我们做了什么呢? 共享内存 众所周知,在处理并发问题上 ...
- 通过node指令自动创建一个package.json文件,并封装发布使用
通过node指令自动创建一个package.json文件,并封装发布使用:https://blog.csdn.net/scu_cindy/article/details/78208268
- hibernate字段映射枚举类型
上一篇介绍了mybatis字段映射枚举类型,这一篇给大家介绍一下hibernate字段怎么去映射枚举类型的(这只是一种参考方式,映射方法还有很多种). 还是以上篇sku表为例,sku表里一个statu ...
- js汉字转换为拼音
片段 1 片段 2 gistfile1.txt /* --- description: Pinyin, to get chinese pinyin from chinese. license: MIT ...
- Numpy 基础函数 --《Python 数据分析从入门到精通》
在Numpy中,方向称作轴,轴的数目称作维.(array(z,y,x)) np.empty() 函数的使用待完全确定.(eg: np.empty([2,3]) -> ([[0,0,0] [0, ...