tensorflow——乘法

  线性代数中,乘法是很重要的运算,具体的矩阵乘法原理可以翻教材,或看一下阮大神的这篇文章:http://www.ruanyifeng.com/blog/2015/09/matrix-multiplication.html。

  在tensorflow中,经常使用以下几种乘法:

  1. 点乘  即常数与向量相乘或向量点乘
    sess = tf.Session()
    
    a = tf.constant([ 0.1, 0.4, 1.2], dtype=tf.float32)
    b = tf.constant([10.0, 5.0, 1.0], dtype=tf.float32)
    
    c = 2.0
    
    print(sess.run(a * b))
    
    print(sess.run(c * a))
  2. 矩阵相乘
    sess = tf.Session()
    
    a = np.random.random((4, 3))
    b = np.random.random((3, 5))
    
    print(sess.run(tf.matmul(a, b)))
  3. 内积
    c = np.random.random((1, 5))
    
    print(sess.run(tf.multiply(b, c)))

  

原文地址:https://www.cnblogs.com/estragon/p/9916304.html