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. php 匿名方法,PHP基于Closure类创建匿名函数的方法详解
  2. GitLab添加SSH Keys并连接(windows)
  3. 【springboot】【若依(ruoyi)】@RestController 接口支持 JSONP
  4. .net 识别一维码_天若OCR文字识别 v5.0 原创好用的OCR及翻译小工具
  5. 微信小程序获取unionid与openid
  6. java原生开发项目-快递e栈
  7. 【转】XP下OpenProcess( PROCESS_ALL_ACCESS...失败
  8. 常用的端口号(port number)
  9. B站 TOP10 Python视频教程
  10. 体悟朝闻道,夕死可以
  11. 机器学习笔记之 K-NEAREST NEIGHBORS
  12. 微信发红包测试用例设计
  13. C++线性表(单链表)的应用算法(附源码)
  14. java动态多态性是通过什么实现的_11.java实现动态多态性是通过()实现的 答案:覆盖...
  15. 适用于主流浏览器导出Excel表格的代码
  16. 年薪30万+的HR这样做数据分析!(附关键指标免费模版)
  17. 计算机仿真文献标识码,【计算机仿真论文】计算机仿真纸币识别体系分析(共4309字)...
  18. WinXP系统下Opencms的安装与配置
  19. Python——飞机大战
  20. Oracle 视图(2)修改视图

热门文章

  1. 以太坊智能合约开发第五篇:字符串拼接—Solidity
  2. 完全总结bash中的条件判断test [ [[ 使用
  3. 转:HTTP ---HTTP头的编码问题(Content-Disposition)
  4. leetcode Largest Rectangle in Histogram 单调栈
  5. 关于unicode,mbcs,utf8,charset,encoding等相关概念的说明
  6. 动态引入js文件和css样式表文件
  7. redis实现订单过期取消
  8. 在html文档中添加 iconfont 图标
  9. linux上apache和php结合
  10. PMP学习笔记之四 第三章 单个项目管理过程