简体   繁体   中英

How to tile a tensor in this way? (Tensorflow)

Origin tensor:

a = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

I want tensor in this way:

result = [[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]]

Using tile api seems not suitable, can anyone help?

Use tf.repeat .

tf.repeat(a, repeats=3, axis=0)
<tf.Tensor: shape=(9, 3), dtype=int32, numpy=
array([[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]])>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM