tf.matmul

转自:https://blog.csdn.net/u013713117/article/details/54598628

矩阵a*b

# 2-D tensor `a`
a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) => [[1. 2. 3.]
                                                      [4. 5. 6.]]
# 2-D tensor `b`
b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) => [[7. 8.]
                                                         [9. 10.]
                                                           [11. 12.]]
c = tf.matmul(a, b) => [[58 64]
                        [139 154]]


  # 3-D tensor `a`
a = tf.constant(np.arange(1,13), shape=[2, 2, 3]) => [[[ 1. 2.  3.]
                                                     [ 4.  5.  6.]],
                                                     [[ 7.  8.  9.]
                                                     [10. 11. 12.]]]

# 3-D tensor `b`
b = tf.constant(np.arange(13,25), shape=[2, 3, 2]) => [[[13. 14.]
                                                        [15. 16.]
                                                        [17. 18.]],
                                                        [[19. 20.]
                                                        [21. 22.]
                                                        [23. 24.]]]
c = tf.matmul(a, b) => [[[ 94 100]
                         [229 244]],
                         [[508 532]
                         [697 730]]]
  • --------------------- 本文来自 mstar1992 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/u013713117/article/details/54598628?utm_source=copy 

猜你喜欢

转载自blog.csdn.net/Candy_GL/article/details/82975331
tf