如何将二维张量与三维十位数合并

2024-09-27 20:17:13 发布

您现在位置:Python中文网/ 问答频道 /正文

在AE lstm中, 这是一个形状为[batch, timestamp, diml](视为[b, t, dl])的lstm out,方面向量为[batch, dima](视为[b, da]

How to concat two variables to make the shape be [b, t, dl+da]?

这意味着对于每个批,concat的方面向量到每个时间戳行


Tags: tobatchout向量timestampdahow形状
1条回答
网友
1楼 · 发布于 2024-09-27 20:17:13

我不是很确定,但我想你想要的是

C = tf.concat([A, tf.tile(tf.expand_dims(B, axis=1), [1, t, 1])], axis=-1)

其中A是lstm,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)

相关问题 更多 >

    热门问题