import tensorflow as tf

 a = tf.constant([1,2,3])
b = tf.constant([4,5,6]) c1 = tf.stack([a,b],axis=0)
c2 = tf.stack([a,b],axis=1)
#take c2 for example showing results of unstack
d1 = tf.unstack(c2,axis=0) # Return: The list of Tensor objects unstacked from value.
d2 = tf.unstack(c2,axis=1) with tf.Session() as sess:
print('c1(with shape:{}):\n{}'.format(c1.shape, sess.run(c1)))
print('c2(with shape:{}):\n{}'.format(c2.shape, sess.run(c2))) print('d1(with length:{}):\n{}'.format(len(d1), sess.run(d1)))
print('d2(with length:{}):\n{}'.format(len(d2), sess.run(d2)))

运行结果:

官方API:

https://www.tensorflow.org/api_docs/python/tf/stack

https://www.tensorflow.org/api_docs/python/tf/unstack

tf.stack和tf.unstack的更多相关文章

  1. tf.concat, tf.stack和tf.unstack的用法

    tf.concat, tf.stack和tf.unstack的用法 tf.concat相当于numpy中的np.concatenate函数,用于将两个张量在某一个维度(axis)合并起来,例如: a ...

  2. tf.stack( )和tf.unstack( )

    相同点:他们都增加了矩阵的维度,而split()不改变维度! tf.stack()这是一个矩阵拼接的函数,tf.unstack()则是一个矩阵分解的函数 c是拼接,而d和e则是不同维度的分解

  3. tf.unstack()、tf.stack()

    tf.unstack 原型: unstack( value, num=None, axis=0, name='unstack' ) 官方解释:https://tensorflow.google.cn/ ...

  4. np.stack() 与 tf.stack() 的简单理解

    说明:np ----> numpy       tf ----> tensorflownp.stack(arrays, axis=0) np.stack(arrays, axis=0) - ...

  5. 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 ...

  6. tf.variable和tf.get_Variable以及tf.name_scope和tf.variable_scope的区别

    在训练深度网络时,为了减少需要训练参数的个数(比如具有simase结构的LSTM模型).或是多机多卡并行化训练大数据大模型(比如数据并行化)等情况时,往往需要共享变量.另外一方面是当一个深度学习模型变 ...

  7. 【TensorFlow基础】tf.add 和 tf.nn.bias_add 的区别

    1. tf.add(x,  y, name) Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, ...

  8. TensorFlow 辨异 —— tf.placeholder 与 tf.Variable

    https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/70 ...

  9. TF.VARIABLE、TF.GET_VARIABLE、TF.VARIABLE_SCOPE以及TF.NAME_SCOPE关系

    1. tf.Variable与tf.get_variable tensorflow提供了通过变量名称来创建或者获取一个变量的机制.通过这个机制,在不同的函数中可以直接通过变量的名字来使用变量,而不需要 ...

随机推荐

  1. java equals与==区别

    java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean   他们之间的比较,应用双等号(== ...

  2. SpringBoot学习之启动方式

    1.通过@SpringBootAppliction注解类启动 启动方法:找到注解类->鼠标右键->run as-> java application. 2 通过maven启动Spri ...

  3. 监听iOS检测屏幕旋转状态,不需开启屏幕旋转

    -(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...

  4. DDR电源硬件设计要点

    一.DDR电源简介 1. 电源 DDR的电源可以分为三类: a.主电源VDD和VDDQ,主电源的要求是VDDQ=VDD,VDDQ是给IO buffer供电的电源,VDD是给但是一般的使用中都是把VDD ...

  5. 数据库ACID操作---事务四原则

    事务操作四原则: 1>原子性:简单来说——整个事务操作如同原子已经是物理上最小的单位,不可分离事务操作要么一起成功,要么一起失败. 2>一致性:倘若事务操作失败,则回滚事务时,与原始状态一 ...

  6. Spark源代码分析之六:Task调度(二)

    话说在<Spark源代码分析之五:Task调度(一)>一文中,我们对Task调度分析到了DriverEndpoint的makeOffers()方法.这种方法针对接收到的ReviveOffe ...

  7. Grails 简要

    一.什么是Grails? Grails is an Open Source, full stack, web application framework for the JVM. It takes a ...

  8. struts2 Eclipse 中集成strust2开发框架实例

    下面通过建立一个小的实例具体来说明Eclipse 集成struts2,以下实例采用的为 struts2 版本为 struts2 2.2.3.1 为应用. 1. 下载struts2的开发包 第一步: 在 ...

  9. TCP/IP状态详解

    今天犯懒了,本来自己也做了一些相应的笔记,但是发现这篇写的更好一些,简单易懂,而且有图有真相,为了方便以后查看,在此转载了,在此基础上加了自己的笔记                 TCP正常建立和关 ...

  10. 给this添加属性

    const f =()=>{ console.log(this) let a=5 console.log(this) console.log(this) this.ak =3} f() let ...