TensorFlow中的tf.batch_matmul()

2022-10-09 11:58:42

如果有两个三阶张量,size分别为

a.shape = [100, 3, 4]

b.shape = [100, 4, 5]

c = tf.batch_matmul(a, b)

则c.shape = [100, 3, 5]  //将每一对 3x4 的矩阵与 4x5 的矩阵分别相乘。batch_size不变

100为张量的batch_size。剩下的两个维度为数据的维度。

不过新版的tensorflow已经移除了上面的函数,使用时换为tf.matmul就可以了。与上面注释的方式是同样的。

附: 如果是更高维度。例如(a, b, m, n) 与(a, b, n, k)之间做matmul运算。则结果的维度为(a, b, m, k)。

  • 作者:yyhhlancelot
  • 原文链接:https://blog.csdn.net/yyhhlancelot/article/details/81191923
    更新时间:2022-10-09 11:58:42