import tensorflow as tf

a = tf.reshape(tf.range(9), [3, 3])
a
tf.pad(a, [[0, 0], [0, 0]])
tf.pad(a, [[
1,
0,
], [0, 0]])
tf.pad(a, [[1, 1], [0, 0]])
tf.pad(a, [[1, 1], [1, 0]])
tf.pad(a, [[1, 1], [1, 1]])
a = tf.random.normal([4, 28, 28, 3])
a.shape
# 对图片的行和列padding两行
b = tf.pad(a, [[0, 0], [2, 2], [2, 2], [0, 0]])
b.shape
a = tf.reshape(tf.range(9), [3, 3])
a
# 1表示行不复制,2表示列复制为两倍
tf.tile(a, [1, 2])
tf.tile(a, [2, 1])
tf.tile(a, [2, 2])
aa = tf.expand_dims(a, axis=0)
aa
tf.tile(aa, [2, 1, 1])
# 不占用内存,性能更优
tf.broadcast_to(aa, [2, 3, 3])

吴裕雄--天生自然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. I2S 总线学习:2-I2S驱动WM8978

    背景 为了了解I2S总线所对应的硬件设计,下文转载了<STM32:I2S驱动WM8978>. 以加深对I2S总线的了解. 正文 最近项目中使用STM32F4驱动音频IC:WM8978. 由 ...

  2. Codestorm:Game with a Boomerang

    题目连接:https://www.hackerrank.com/contests/codestorm/challenges/game-with-a-boomerang 上一篇博客不知怎么复制过来题目, ...

  3. JS写一个漂亮的音乐播放器

    先放上效果图: 正如图中所展示的播放器那样,我们用HTML+CSS+JS将这个效果实现出来. HTML页面布局 <div class="music"> <div ...

  4. jenkins#安装jenkins之后的操作

    1.全局安全配置 运行用户注册 任何用户可以做任何事情 2.全局工具配置 指定maven的settings文件位置 指定java信息 指定maven信息 指定git信息

  5. 06.swoole学习笔记--异步tcp服务器

    <?php //创建tcp服务器 $host='0.0.0.0'; $port=; $serv=new swoole_server($host,$port); //设置异步进程工作数 $serv ...

  6. 016、Java中使用小数

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  7. leetcode1302 Deepest Leaves Sum

    """ Given a binary tree, return the sum of values of its deepest leaves. Example 1: I ...

  8. ①spring简介以及环境搭建(一)

    注*(IOC:控制反转.AOP:面向切面编程) spring官网:http://spring.io/ spring简介: spring是一个开源框架 spring为简化企业级应用开发而生,使用Spri ...

  9. Netty 模型

    Demo代码 使用Maven的话请在pom.xml中注入netty依赖 <!-- https://mvnrepository.com/artifact/io.netty/netty-all -- ...

  10. 吴裕雄--天生自然java开发常用类库学习笔记:一对多关系范例

    import java.util.List ; import java.util.ArrayList ; public class School{ private String name ; priv ...