一、环境
TensorFlow API r1.12
CUDA 9.2 V9.2.148
cudnn64_7.dll
Python 3.6.3
Windows 10
二、官方说明
根据指定的维度重复输入张量多次
https://tensorflow.google.cn/api_docs/python/tf/tile
输出的第 i 维具有 input.dims(i) * multiples[i] 个元素
输入值沿着维度 i 被重复 multiples[i] 次
tf.tile(
input,
multiples,
name=None
)
参数:
input:1 维及1 维以上的张量
multiples:张量,必须为 int32 或 int64 类型,长度必须与 input 的维度数量相同
name:可选参数,操作的名称
返回:
类型与 input 相同的张量
三、实例
data:2 行 3 列矩阵
tiled_data:按照 multiples 中对行重复 2 次,对列重复 3 次,因此就是 4 行 9 列数据
>>> import tensorflow as tf
>>> data = tf.constant(value=[[1,2,3],[4,5,6]])
>>> data
<tf.Tensor 'Const_4:0' shape=(2, 3) dtype=int32>
>>> tiled_data = tf.tile(input=data, multiples=[2,3])
>>> tiled_data
<tf.Tensor 'Tile_3:0' shape=(4, 9) dtype=int32>
>>> sess = tf.InteractiveSession()
>>> print(sess.run(fetches=[data, tiled_data]))
[array([[1, 2, 3],
[4, 5, 6]]), array([[1, 2, 3, 1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6, 4, 5, 6],
[1, 2, 3, 1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6, 4, 5, 6]])]
>>> sess.close()