吴裕雄--天生自然TensorFlow2教程:合并与分割
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教程:合并与分割的更多相关文章
- 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...
- 吴裕雄--天生自然TensorFlow2教程:函数优化实战
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...
- 吴裕雄--天生自然TensorFlow2教程:反向传播算法
- 吴裕雄--天生自然TensorFlow2教程:链式法则
import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...
- 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...
- 吴裕雄--天生自然TensorFlow2教程:损失函数及其梯度
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...
- 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度
import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...
- 吴裕雄--天生自然TensorFlow2教程:梯度下降简介
import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as ...
随机推荐
- 【转载】Jmeter关联-正则表达式提取器
今天研发同事提供了一个验证token的接口,要验证token的正确性,现在将整个过程做如下记录: 场景:验证token的正确性 原理:首先用户登录成功后,会在Response head ...
- REVISITING FINE-TUNING FOR FEW-SHOT LEARNING
https://arxiv.org/pdf/1910.00216.pdf 明天看
- Centos7关闭防火墙 设置开机启动
[root@nmserver-7 ~]# systemctl stop firewalld.service [root@nmserver-7 ~]# systemctl status firewall ...
- 原生JS写表单验证提交功能
先上效果图: 表单的基础内容就是昵称判断.手机号判断.邮箱判断.身份证号码判断,这里是用到正则验证检验格式. 页面的表单写法就是一个form的提交.输入框用input来实现,输入内容用value来获取 ...
- 【Jasypt】给你的配置加把锁
前言 前几天,有个前同事向我吐槽,他们公司有个大神把公司的项目代码全部上传到了 github,并且是公开项目,所有人都可以浏览.更加恐怖的是项目里面包含配置文件,数据库信息.redis 配置.各种公钥 ...
- Python中语法糖及带参语法糖
在python中,@符号常被称作语法糖(装饰器),在某函数定义时,用以包装该函数,以达到截取,控制该函数的目的. def d(f): print('d...') k=f #此处保留了传进来的原函数 f ...
- ubuntu18.04下载yarn
下载curl sudo apt-get update && sudo apt-get install curl 配置库 curl -sS https://dl.yarnpkg.com/ ...
- Django(六)实战2:向数据库添加,删除数据、重定向写法、重定向简写
一.向数据库添加图书数据 [上接]https://blog.csdn.net/u010132177/article/details/103831173 1)首先开启mysql服务,并运行项目 启动my ...
- 吴裕雄--天生自然java开发常用类库学习笔记:比较器
class Student implements Comparable<Student> { // 指定类型为Student private String name ; private i ...
- 《ES6标准入门》(阮一峰)--3.变量的解构赋值
1.数组的解构赋值 基本用法 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; l ...