介绍
传入tensor,让其在某个轴上复制
语法
tf.tile(
input,
multiples,
name=None
)
参数
- input:tensor
- multiples:必须是int32, int64类型之一。
如果input是1维,那么multiples长度必须1
例子
一维
a = tf.constant([1,2])
b = tf.tile(a,[3])
print(b)
执行结果:
tf.Tensor([1 2 1 2 1 2], shape=(6,), dtype=int32)
注意:
由于a是1维,所以multiples长度必须1
二维 在0轴上复制
import tensorflow as tf
a = tf.constant([[1,2],[3,4]])
c=tf.tile(a,[2,1])
print(c)
在0轴上复制2次,执行结果:
tf.Tensor(
[[1 2]
[3 4]
[1 2]
[3 4]], shape=(4, 2), dtype=int32)
二维 在1轴上复制
import tensorflow as tf
a = tf.constant([[1,2],[3,4]])
d=tf.tile(a,[1,2])
print(d)
在1轴上复制2次,执行结果:
tf.Tensor(
[[1 2 1 2]
[3 4 3 4]], shape=(2, 4), dtype=int32)
二维 在0轴和1轴上复制
a = tf.constant([[1,2],[3,4]])
b = tf.tile(a,[2,3])
print(b)
在0轴上复制2次,在1轴上复制3次,执行结果:
tf.Tensor(
[[1 2 1 2 1 2]
[3 4 3 4 3 4]
[1 2 1 2 1 2]
[3 4 3 4 3 4]], shape=(4, 6), dtype=int32)