TensorFlow:如何对向量和张量进行点积?

问题描述

我在shape=(n,)的TF中有一个向量(表示一维张量):

my_vector = tf.random.uniform(shape=[n])

我有一个shape=(m,n)的张量:

my_tensor = tf.random.uniform(shape=[m,n])

我想用my_tensormy_vector的每一行进行点积,并从点积中获得shape=(m,)向量。我该怎么办?

我将其元素形象化了。

enter image description here

解决方法

尝试一下

tf.tensordot(my_tensor,my_vector,1)