tf.tile(input, multiples, name=None)
作用是吧input按照multiples的要求复制,构建新的tensor
注意:multiples中的元素个数必须跟input的维度相同,不然会报错
import tensorflow as tf
a = tf.constant([1,2,3])
b = tf.constant([[4,5,6],[7,8,9]])
c = tf.tile(input=a, multiples=[2])
d = tf.tile(input=[a], multiples=[2,3])
f = tf.tile(input=b, multiples=[2,3])
with tf.Session() as sess:
print (sess.run(c),'\n')
print (sess.run(d),'\n')
结果
[1 2 3 1 2 3]
[[1 2 3 1 2 3 1 2 3]
[1 2 3 1 2 3 1 2 3]]
[[4 5 6 4 5 6 4 5 6]
[7 8 9 7 8 9 7 8 9]
[4 5 6 4 5 6 4 5 6]
[7 8 9 7 8 9 7 8 9]]