Happy_Zhou
Happy_Zhou

Reputation: 21

Using tf.tile or tf.expand_dims to replicate a tensor in some way

Based on tensorflow functions. There is a tensor A=[1 10 5 6]. How could I create a tensor B which looks like the following:

[[[1  1  1 ],[1  1  1 ],[1  1  1 ]],
 [[10 10 10],[10 10 10],[10 10 10]],
 [[5  5  5 ],[5  5  5 ],[5  5  5 ]],
 [[6  6  6 ],[6  6  6 ],[6  6  6 ]]]

Thanks.

Upvotes: 0

Views: 456

Answers (1)

Happy_Zhou
Happy_Zhou

Reputation: 21

A_reshape = tf.expand_dims(A,1)
A_reshape = tf.expand_dims(A_reshape,2)
B = tf.tile(A_reshape, [1,3,3])

Upvotes: 1

Related Questions