1. tf.repeat
>>> a = tf.repeat(['a', 'b', 'c'], repeats=[3, 1, 2], axis=0)
[b'a' b'a' b'a' b'b' b'c' b'c']
>>> a = tf.repeat(['a', 'b', 'c'], repeats=[3, 1, 2], axis=1)
[b'a' b'a' b'a' b'c' b'c']
>>> out = tf.repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=0)
[[1 2]
[1 2]
[3 4]
[3 4]
[3 4]]
>>> out = tf.repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=1)
[[1 1 2 2 2]
[3 3 4 4 4]]
2. tf.stack
>>> x = tf.constant([1, 4])
>>> y = tf.constant([2, 5])
>>> z = tf.constant([3, 6])
>>> out = tf.stack([x, y, z]) # 默认横坐标拼接
[[1 4]
[2 5]
[3 6]]
>>> out = tf.stack([x, y, z], axis=1) # 按纵坐标拼接
[[1 2 3]
[4 5 6]]
3.tf.tile
>>> a = tf.constant([[1,2,3],[4,5,6]], tf.int32)
>>> b = tf.constant([1,2], tf.int32)
>>> tf.tile(a, b)
[[1,2,3,1,2,3],
[4,5,6,4,5,6]
]
>>> d = tf.constant([2,2], tf.int32)
>>> tf.tile(a, d)
[[1,2,3,1,2,3],
[4,5,6,4,5,6],
[1,2,3,1,2,3],
[4,5,6,4,5,6]
]
4. tf.concat
>>> t1 = [[1, 2, 3], [4, 5, 6]]
>>> t2 = [[7, 8, 9], [10, 11, 12]]
>>> tf.concat([t1, t2], axis=0)
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
]
>>> tf.concat([t1, t2], 1)
[[1, 2, 3, 7, 8, 9],
[4, 5, 6, 10, 11, 12]
]