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. 命令打开java控制面板

    运行一些java程序时,会提示java安全阻止,需要手动运行,java7一起更改安全级别为“中”就可以了,java8需要配置信任网站 . 这些操作都需要在java控制面板进行,经常会出现无法在控制面板 ...

  2. 对象内置的方法/内置的 Symbol 值

    内置的 Symbol 值 除了定义自己使用的 Symbol 值以外,ES6 还提供了 11 个内置的 Symbol 值,指向语言内部使用的方法. Symbol.hasInstance 对象的Symbo ...

  3. HTML学习第五天

    HTML学习第五天 今天学HTML的实体.背景.布局 HTML布局的标签基本被淘汰frameset就被淘汰了,只有iframe依然存活,但是iframe可以被CSS给代替.下面就是一个练习的程序 &l ...

  4. GNS3 模拟免费ARP

    R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...

  5. 机器阅读理解(看各类QA模型与花式Attention)(转载)

    目录 简介 经典模型概述 Model 1: Attentive Reader and Impatient Reader Attentive Reader Impatient Reader Model ...

  6. 066、Java面向对象之以分步的方式实例化对象

    01.代码如下: package TIANPAN; class Book { // 定义一个新的类 String title; // 书的名字 double price; // 书的价格 public ...

  7. 017、MySQL取第4本季度开始和结束日期

    #取第4本季度开始和结束日期 SELECT QUARTER ( adddate( dy, ) ) QTR, date_add( dy, INTERVAL MONTH ) Q_start, adddat ...

  8. 从MSSQL表中删除重复项

    declare @ids int=1 declare @count int while @ids<471 begin select @count=COUNT(*) From LotNO wher ...

  9. redis改配置

    命令行: 暂时生效,适合于做测试,或者线上马上服务修改,重启失效 CONFIG set stop-writes-on-bgsave-error no OK CONFIG get stop-writes ...

  10. 在windows7 64位上安装selenium2library问题解决

    今天发现了windows7 64位上安装selenium2Libaray的问题,下载exe文件安装不行.就切换成了半自动模式.  方案如下: 1.首先下载pip安装.(因为要用pip来安装 selen ...