Dot product of two vectors in tensorflow

前端 未结 9 1169
悲&欢浪女
悲&欢浪女 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:38

    In newer versions (I think since 0.12), you should be able to do

    tf.einsum('i,i->', x, y)
    

    (Before that, the reduction to a scalar seemed not to be allowed/possible.)

提交回复
热议问题