TensorFlow张量上tensordot运算的数学定义

TensorFlow张量上tensordot运算的数学定义,tensorflow,tensor,axes,dot-product,multiple-axes,Tensorflow,Tensor,Axes,Dot Product,Multiple Axes,我正在尝试对tf.tensordot axes参数的行为进行反向工程,但遇到了困难 给定以下代码: a = tf.constant([[1., 2.], [3., 4.], [4., 5.]]) b = tf.constant([1., 2.]) c = tf.constant([[1., 2.], [2., 3.], [3., 4.]]) print(f'Shape of c: {c.shape}') ct = tf.transpose(c) print(f'Shape of ct: {

我正在尝试对tf.tensordot axes参数的行为进行反向工程,但遇到了困难

给定以下代码:

a = tf.constant([[1., 2.], [3., 4.], [4., 5.]])
b = tf.constant([1., 2.])
c = tf.constant([[1., 2.], [2., 3.], [3., 4.]])

print(f'Shape of c: {c.shape}')

ct = tf.transpose(c)

print(f'Shape of ct: {ct.shape}')

print('.................')

d = tf.tensordot(a, ct, axes=1)
print(f'Shape of d: {d.shape}')
print(d)

print('.................')


e = tf.tensordot(a, ct, axes=0)
print(f'Shape of e: {e.shape}')
print(e)


print('.................')


f = tf.tensordot(a, ct, axes=2)
print(f'Shape of f: {f.shape}')
print(e)

我知道“d”是如何产生的,但我不知道“e”和“f”是如何产生的。这不足以让我理解。

我发布了Axis可以采用的参数子集的中间答案(当Axis为整数时):

轴=0: 没有加法,只有乘法。例如:

c = tf.tensordot(a, b, axes=0)
这意味着如果a的形状是m,n,b的形状是o,p,那么c的形状是m,n,o,p,因为元素是相乘的,但不是求和的

轴=1:

如果a的形状是m,n,b的形状是n,o,那么c的形状是m,o,因为元素是相乘的,但也是求和的

一旦我了解了更多关于这个主题的内容,我将更新这篇文章

c = tf.tensordot(a, b, axes=1)