吴裕雄--天生自然TensorFlow2教程:填充与复制

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])
原文地址:https://www.cnblogs.com/tszr/p/12133523.html