如果需要扩展一个(N, 1)的向量为(N, M)的矩阵,可以用tf.tile()和tf.expand_dims()
import tensorflow as tf
print(tf.__version__)
a = tf.constant([1, 2, 3, 4], dtype=tf.float32)
a0 = tf.expand_dims(a, 0)
a1 = tf.tile(a0, [2, 1])
with tf.Session() as sess:
print(sess.run(a))
print(sess.run(a0))
print(sess.run(a1))
=======
'1.13.1'
[1, 2, 3, 4]
[[1, 2, 3, 4]]
[[1, 2, 3, 4], [1, 2, 3, 4]]
ref:
直观的理解tensorflow中的tf.tile()函数
TensorFlow中张量转置操作tf.expand_dims用法