Dot product of two vectors in tensorflow

前端 未结 9 1175
悲&欢浪女
悲&欢浪女 2021-01-01 12:36

I was wondering if there is an easy way to calculate the dot product of two vectors (i.e. 1-d tensors) and return a scalar value in tensorflow.

Given two vectors X=(

9条回答
  •  死守一世寂寞
    2021-01-01 12:41

    Let us assume that you have two column vectors

    u = tf.constant([[2.], [3.]])
    v = tf.constant([[5.], [7.]])
    

    If you want a 1x1 matrix you can use

    tf.einsum('ij,ik->jk',x,y)
    

    If you are interested in a scalar you can use

    tf.einsum('ij,ik->',x,y)
    

提交回复
热议问题