tensorflow - replicate a row tensor using tf.tile? -
i have tensor vector, vector = [0.5 0.4]
, tf.shape indicates has shape=(1,), replicate vector m times , have shape of [m, 2], m = 2, matrix = [[0.5 0.4], [0.5 0.4]]
. how achieve using tf.tile?
take following, vec vector, multiply m, number of times repeat vec. tile performed on vector , result reshaped desired structure.
import tensorflow tf vec = tf.constant([1, 2, 3, 4]) multiply = tf.constant([3]) matrix = tf.reshape(tf.tile(vec, multiply), [ multiply[0], tf.shape(vec)[0]]) tf.session() sess: print(sess.run([matrix]))
this results in:
[array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]], dtype=int32)]
Comments
Post a Comment