tensorflow tf.tile 使用教程·

时间: 2023-07-09 admin 互联网

tensorflow tf.tile 使用教程·

tensorflow tf.tile 使用教程·

该方法将张量按照指定的维度复制多份

a = tf.constant([[1, 2, 3], [4, 5, 6]], tf.int32)
b = tf.constant([3, 2], tf.int32)
print(a)
print(b)
print(tf.tile(a, b))

张量a的维度是[2,3]   b的维度是一维张量 [2,],取值的[3,2]

tf.Tensor(
[[1 2 3]
 [4 5 6]], shape=(2, 3), dtype=int32)


tf.Tensor([3 2], shape=(2,), dtype=int32)

复制出来的结果维度是 【2*3,3*2】=【6,6】

tile(a,b) 将a的第一维按照b的第一个数复制,a的第二维按照b的第二个数复制

第一维
tf.Tensor(
[[1 2 3 1 2 3]
 [4 5 6 4 5 6]
 [1 2 3 1 2 3]
 [4 5 6 4 5 6]
 [1 2 3 1 2 3]
 [4 5 6 4 5 6]], shape=(6, 6), dtype=int32)