tf.multiply()和tf.matmul()区别

  1. tf.multiply是点乘,即Returns x * y element-wise,支持broadcasting
  2. tf.matmul是矩阵乘法,即Multiplies matrix a by matrix b, producing a * b.

示例:

import tensorflow as tf
import pprint
a = tf.reshape(tf.constant([1,2,3,4,5,6]), [2,3])
b = tf.reshape(tf.constant([1,2,3,4,5,6]), [3,2])
c = tf.reshape(tf.constant([1,2,3,4,5,6]), [2,3])

x = tf.matmul(a, b)
y = a * c
z = tf.multiply(a,c)

with tf.Session() as sess:
    pprint.pprint(sess.run([a,b,c, x, y,z]))

输出:

[array([[1, 2, 3],
       [4, 5, 6]], dtype=int32),
 array([[1, 2],
       [3, 4],
       [5, 6]], dtype=int32),
 array([[1, 2, 3],
       [4, 5, 6]], dtype=int32),
 array([[22, 28],
       [49, 64]], dtype=int32),
 array([[ 1,  4,  9],
       [16, 25, 36]], dtype=int32),
 array([[ 1,  4,  9],
       [16, 25, 36]], dtype=int32)]
阅读更多
个人分类: Python Tensorflow
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭