tensorflow中的tile()函数是用来对张量(Tensor)进行扩展的,其特点是对当前张量内的数据进行一定规则的复制。最终的输出张量维度不变。
语法:
tf.tile
(
input,
multiples,
name=None
)
- input - 待拓展的张量
- multiples - 拓展的倍数
如果input是一个3维的张量,那multiples就是一个1×3的一维张量。这三个值分别代表input三维中的倍数。
示例
import tensorflow as tf
import numpy as np
a = tf.constant([[1,2,3],[4,5,6]], tf.int32)
b = tf.constant([1,2], tf.int32)
result = tf.tile(a, b)
result.numpy()
# array([[1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6]])
d = tf.constant([2,2], tf.int32)
result2 = tf.tile(a, d)
result2.numpy()
# array([[1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6],
# [1, 2, 3, 1, 2, 3],
# [4, 5, 6, 4, 5, 6]])