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=(
ab = tf.reduce_sum(a*b)
Take a simple example as follows:
import tensorflow as tf
a = tf.constant([1,2,3])
b = tf.constant([2,3,4])
print(a.get_shape())
print(b.get_shape())
c = a*b
ab = tf.reduce_sum(c)
with tf.Session() as sess:
print(c.eval())
print(ab.eval())
# output
# (3,)
# (3,)
# [2 6 12]
# 20