import tensorflow as tf

# 6个班级的学生分数情况
a = tf.ones([4, 35, 8])
b = tf.ones([2, 35, 8])
c = tf.concat([a, b], axis=0)
c.shape
# 3个学生学生补考
a = tf.ones([4, 32, 8])
b = tf.ones([4, 3, 8])
tf.concat([a, b], axis=1).shape
a = tf.ones([4, 35, 8])
b = tf.ones([4, 35, 8])
a.shape
b.shape
tf.concat([a, b], axis=-1).shape
tf.stack([a, b], axis=0).shape
tf.stack([a, b], axis=3).shape
a = tf.ones([4, 35, 8])
b = tf.ones([3, 33, 8])
try:
tf.concat([a, b], axis=0).shape
except Exception as e:
print(e)
# concat保证只有一个维度不相等
b = tf.ones([2, 35, 8])
c = tf.concat([a, b], axis=0)
c.shape
# stack保证所有维度相等
try:
tf.stack([a, b], axis=0)
except Exception as e:
print(e)
a.shape
b = tf.ones([4, 35, 8])
c = tf.stack([a, b])
c.shape
aa, bb = tf.unstack(c, axis=0)
aa.shape, bb.shape
# [2,4,35,8]
res = tf.unstack(c, axis=3)
# 8个[2, 4, 35]的Tensor
res[0].shape, res[1].shape, res[7].shape
# [2,4,35,8]
res = tf.unstack(c, axis=2)
# 35个[2, 4, 8]的Tensor
res[0].shape, res[1].shape, res[34].shape
# 8个Tensor,全为1
res = tf.unstack(c, axis=3)
len(res)
# 2个Tensor,一个6、一个2
res = tf.split(c, axis=3, num_or_size_splits=2)
len(res)
res[0].shape
res = tf.split(c, axis=3, num_or_size_splits=[2, 2, 4])
res[0].shape, res[1].shape, res[2].shape

吴裕雄--天生自然TensorFlow2教程:合并与分割的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  2. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  3. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

  4. 吴裕雄--天生自然TensorFlow2教程:链式法则

    import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...

  5. 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  6. 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

  7. 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  8. 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度

    import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...

  9. 吴裕雄--天生自然TensorFlow2教程:梯度下降简介

    import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as ...

随机推荐

  1. 白手起家Django项目发布下篇_Django项目nginx部署

    上一篇完成了python的安装,接下来安装python的依赖包和项目的依赖包 1.  python-devel 命令:yum -y install python-devel 安装Django1.8.2 ...

  2. Ubuntu操作系统编写zabbix的启动管理脚本

    Ubuntu操作系统编写zabbix的启动管理脚本 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.修改zabbix的pid存放路径 1>.创建存放zabbix的pid目录 ...

  3. mongdb 4.x admin密码忘记,如何 重建admin用户

    在mongo db中,或mongo db cluser中,如果admin密码忘记了,必须按下面的步骤来做.思路为注释掉security认证部分,重启mongo server, 重建admin用户,再打 ...

  4. POJ 3259:Wormholes bellman_ford判定负环

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 37906   Accepted: 13954 Descr ...

  5. WEB-INF

    WEB-INF下的内容是没有办法通过浏览器去请求的.可以把东西放在WEB-INF下面,避免用户直接通过浏览器请求.那些资源只允许通过url请求过来通过其他途径转发给用户. 比如WEB-INF/jsp/ ...

  6. tools.windows.bat#批处理

    关于%~ %~I - 删除任何引号("),扩展 %I %~fI - 将 %I 扩展到一个完全合格的路径名 %~dI - 仅将 %I 扩展到一个驱动器号 %~pI - 仅将 %I 扩展到一个路 ...

  7. 用python实现在手机查看小姐姐的电脑在作什么!

    看上心意的小姐姐,想看她平时都浏览什么网页,如何才能看她的桌面呢,都说Python很厉害,这次我们做一个利用移动端访问电脑来查看电脑的界面的神器!不知道大家以前有没有做过这方面的东西呢?也许大家听起来 ...

  8. postgres http fdw + plv8 处理数据

    原理很简单就是就有http fdw 获取数据,然后结合plv8 处理json 数据 环境准备 docker-compose 文件 version: "3" services:  p ...

  9. S7-200 smart输入输出接口试验

    工具 西门子 s7-200smart PLC 西门子s7-200 smart 试验 CPU型号是 SR30 这个 编译环境 符号 选择 了 "输入1"以后, 会自动的编地址为I0. ...

  10. netty权威指南学习笔记一——NIO入门(2)伪异步IO

    在上一节我们介绍了四种IO相关编程的各个特点,并通过代码进行复习了传统的网络编程代码,伪异步主要是引用了线程池,对BIO中服务端进行了相应的改造优化,线程池的引入,使得我们在应对大量客户端请求的时候不 ...