当轴使用不同的参数时如何理解 tf.tensordot?

问题描述

我只是在研究 Tensorflow。并对 tensordot 感到困惑。比如我的代码是:

import tensorflow as tf
a=tf.Variable([[1,2],[4,5],[7,8]])
b=tf.Variable([[1,8]])

根据 tf.tensordot 中不同的轴参数,结果不同。

tf.tensordot(a,b,axes=0)
<tf.Tensor: shape=(3,2,3,2),dtype=int32,numpy=
array([[[[ 1,[ 4,[ 7,8]],[[ 2,4],[ 8,10],[14,16]]],[[[ 4,8],[16,20],[28,32]],[[ 5,[20,25],[35,40]]],[[[ 7,14],35],[49,56]],[[ 8,16],[32,40],[56,64]]]],dtype=int32)>

tf.tensordot(a,axes=0)
InvalidArgumentError: Matrix size-incompatible: In[0]: [3,In[1]: [3,2] [Op:MatMul]

tf.tensordot(a,axes=2)
<tf.Tensor: shape=(),numpy=159>

虽然看了一些解释,但还是没看懂。它是如何工作的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)