简体   繁体   English

3d乘2d矩阵Tensorflow

[英]3d times 2d matrices Tensorflow

Suppose I have two tensors of different dimensions. 假设我有两个不同尺寸的张量。

<tf.Tensor 'embedding_lookup:0' shape=(?, 128) dtype=float32>
<tf.Tensor 'Neg:0' shape=(?, 15, 128) dtype=float32>

I want to do a matrix multiplication of these two tensors such that I get a final tensor with shape (?, 15, 1) or (?, 15) . 我想对这两个张量进行矩阵乘法,以便得到形状为(?, 15, 1)(?, 15)的最终张量。 How could I do this? 我该怎么办?

With X and Y as the 2D and 3D inputs respectively, we can use tf.einsum - 分别使用XY作为2D3D输入,我们可以使用tf.einsum

tf.einsum('ij,ikj->ik',X,Y)

The output would have a shape of (?, 15) . 输出将具有(?, 15)的形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM