2024-09-27 20:17:13 发布
网友
在AE lstm中, 这是一个形状为[batch, timestamp, diml](视为[b, t, dl])的lstm out,方面向量为[batch, dima](视为[b, da])
[batch, timestamp, diml]
[b, t, dl]
[batch, dima]
[b, da]
How to concat two variables to make the shape be [b, t, dl+da]?
[b, t, dl+da]
这意味着对于每个批,concat的方面向量到每个时间戳行
我不是很确定,但我想你想要的是
C = tf.concat([A, tf.tile(tf.expand_dims(B, axis=1), [1, t, 1])], axis=-1)
其中A是lstm,B是方面向量。我通过简单地检查尺寸来验证它,这似乎是正确的。看看这是不是你真正需要的
A
B
编辑:为了清楚起见,这是我用来测试的全部代码:
import tensorflow as tf b = 5 t = 10 dl = 15 da = 12 A = tf.ones(shape=(b, t, dl)) B = tf.ones(shape=(b, da)) C = tf.concat([A, tf.tile(tf.expand_dims(B, axis=1), [1, t, 1])], axis=-1) print(C)
给出了预期的输出:
Tensor("concat:0", shape=(5, 10, 27), dtype=float32)
我不是很确定,但我想你想要的是
其中
A
是lstm,B
是方面向量。我通过简单地检查尺寸来验证它,这似乎是正确的。看看这是不是你真正需要的编辑:为了清楚起见,这是我用来测试的全部代码:
给出了预期的输出:
相关问题 更多 >
编程相关推荐