1.stack操作

先看一下tensorflow中stack方法的函数签名

@tf_export("stack")
@dispatch.add_dispatch_support
def stack(values, axis=0, name="stack"):"""Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor.See also `tf.concat`, `tf.tile`, `tf.repeat`.Packs the list of tensors in `values` into a tensor with rank one higher thaneach tensor in `values`, by packing them along the `axis` dimension.Given a list of length `N` of tensors of shape `(A, B, C)`;if `axis == 0` then the `output` tensor will have the shape `(N, A, B, C)`.if `axis == 1` then the `output` tensor will have the shape `(A, N, B, C)`.Etc........

stack操作是将一组秩为R的tensor叠成一个秩为R+1的tensor。

def stack_operation():x = tf.constant([1, 4])y = tf.constant([2, 5])z = tf.constant([3, 6])s1 = tf.stack([x, y, z])print(s1)s2 = tf.stack([x, y, z], axis=1)print(s2)

代码输出为:

tf.Tensor(
[[1 4][2 5][3 6]], shape=(3, 2), dtype=int32)
tf.Tensor(
[[1 2 3][4 5 6]], shape=(2, 3), dtype=int32)

其中,axis指定为对哪个维度进行操作。如果axis=0,改变的则是最外层的维度,以此类推。

2.unstack

理解了上面的stack操作,unstack就好理解了,就是stack的逆操作。

def unstack_operation():s = tf.constant([[1, 2, 3], [4, 5, 6]])a = tf.unstack(s, axis=0)b = tf.unstack(s, axis=1)print(a)print(b)
[<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 2, 3], dtype=int32)>, <tf.Tensor: shape=(3,), dtype=int32, numpy=array([4, 5, 6], dtype=int32)>]
[<tf.Tensor: shape=(2,), dtype=int32, numpy=array([1, 4], dtype=int32)>, <tf.Tensor: shape=(2,), dtype=int32, numpy=array([2, 5], dtype=int32)>, <tf.Tensor: shape=(2,), dtype=int32, numpy=array([3, 6], dtype=int32)>]

tensorflow stack unstack操作相关推荐

  1. 深度学习(12)TensorFlow高阶操作一: 合并与分割

    深度学习(12)TensorFlow高阶操作一: 合并与分割 1. concat 2. stack: create new dim 3. Dim mismatch 4. unstuck 5. spli ...

  2. 深度学习(17)TensorFlow高阶操作六: 高阶OP

    深度学习(17)TensorFlow高阶操作六: 高阶OP 1. Where(tensor) 2. where(cond, A, B) 3. 1-D scatter_nd 4. 2-D scatter ...

  3. 【Tensorflow】io 操作

    文章首发于微信公众号<有三AI> [从caffe到Tensorflow 1]io 操作 最近项目要频繁用到tensorflow,所以不得不认真研究下tensorflow而不是跟之前一样遇到 ...

  4. 深度学习(16)TensorFlow高阶操作五: 张量限幅

    深度学习(16)TensorFlow高阶操作五: 张量限幅 1. clip_by_value 2. relu 3. clip_by_norm 4. Gradient clipping 5. 梯度爆炸实 ...

  5. 深度学习(15)TensorFlow高阶操作四: 填充与复制

    深度学习(15)TensorFlow高阶操作四: 填充与复制 1. Pad 2. 常用于Image Padding 3. tile 4. tile VS broadcast_to Outline pa ...

  6. 深度学习(14)TensorFlow高阶操作三: 张量排序

    深度学习(14)TensorFlow高阶操作三: 张量排序 一. Sort, argsort 1. 一维Tensor 2. 多维Tensor 二. Top_k 三. Top-k accuracy(To ...

  7. tensorflow随笔——concat(), stack(), unstack()

    tf.concat用于将多个张量在某维度合并起来,类似于numpy.concatenate.第一个参数为待合并的多个张量列表,第二个参数需指定哪个维度上做合并.待合并的张量shape需要完全相同,并且 ...

  8. tensorflow.unstack() and tensorflow.stack()

    https://www.jianshu.com/p/25706575f8d4 tensorflow API https://tensorflow.google.cn/api_docs/python/t ...

  9. tensorflow.unstack() 与 tensorflow.stack()

    https://blog.csdn.net/qq_31150463/article/details/84193975 https://www.jianshu.com/p/25706575f8d4

  10. tensorflow之复数操作

    1.TensorFlow复数操作 查看全文 http://www.taodudu.cc/news/show-4764309.html 相关文章: 实现复数类中的运算符重载 九度1178 阶乘 c语言 ...

最新文章

  1. Python 的 time 模块导入及其方法
  2. Spring @Autowired、@Resource、@Required、@Component、@Repository、@Service、@Controller注解的用法和作用...
  3. python线程创建对象_Python多线程编程基础:如何创建线程?
  4. puppet应用原理及安装部署
  5. C#网络编程概述 二
  6. Java 14 来了!
  7. 半监督学习(semi-supervised learning)
  8. “菁客”发布《2018中国移动社交招聘趋势报告》
  9. python3 读取.plist文件_python读写plist文件
  10. 【CF335E】 Counting Skyscrapers(期望)
  11. 能上QQ不能上网的解决方法
  12. 计算机配色软件开发,电脑配色软件各个行业的应用
  13. ROS下使用C++读取txt文本数据并使用
  14. vue中父元素点击事件与子元素点击事件冲突
  15. SSO(single sign on)模式 单点登录
  16. 解决问题就是有成就感
  17. 东北农业大学计算机科学与技术复试名单,复试通知来了!150余所高校已发布最新复试信息!...
  18. 获取cron表达式 下次执行时间 和 执行间隔
  19. 实验二、数据库的建立和维护
  20. qt通过Tcp和SQL实现仿qq的聊天软件

热门文章

  1. 使用Istio分布式跟踪应用程序
  2. 【二 HTTP编程】2. HTTP路由
  3. 4.4 Hibernate高级功能
  4. WinCE6.0下TCPMP的BenchMark汇总
  5. T-SQL数据类型的细微差别(四)
  6. Cannot detect Web Project version. Please specify version of Web Project through Maven project ...报错
  7. 使用 jdbc 从数据库中查询数据
  8. 你知道Object中有哪些方法及其作用吗?
  9. noip普及组2018T2 龙虎斗
  10. webserver/CGI