戴斯铭
戴斯铭

Reputation: 11

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?

Upvotes: 0

Views: 140

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36624

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]])>

Upvotes: 1

Related Questions