【问题标题】:Mathematical definition of tensordot operation on TensorFlow tensorTensorFlow张量上张量点运算的数学定义
【发布时间】:2019-12-20 15:48:32
【问题描述】:

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

给定以下代码:

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”是如何产生的。 TensorFlow Documentation 不足以让我理解。

【问题讨论】:

    标签: tensorflow tensor axes dot-product multiple-axes


    【解决方案1】:

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

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

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

    这意味着如果 a 的形状为 m,n,b 的形状为 o,p,则 c 的形状为 m,n,o,p,因为元素相乘,但没有相加

    = 1:

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

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

    一旦我了解了有关该主题的更多信息,将更新此帖子

    【讨论】:

      猜你喜欢
      • 2019-08-18
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      • 2017-05-25
      相关资源
      最近更新 更多