首页 > 解决方案 > 理解 shape=(1,) 张量

问题描述

我有一个张量“idx”,它作为下面代码的结果返回。该代码使用了另外三个名为“result”、“theta”和“user”的张量,它们都在下面的输出中描述。我对 tensorflow 很陌生,我试图了解 idx 是什么,文档对 shape=(1,) 的含义有点不清楚。是向量还是矩阵?有没有办法访问 idx 的元素?我尝试了 idx[1] 或 idx[1,] 但我得到了超出范围的错误。

非常感谢任何提示。

Code:

result

Output:

<tf.Tensor 'DVBPR_1/Add_2:0' shape=(1, 100) dtype=float32>

Code:

thetau

Output:

<tf.Variable 'DVBPR/Variable:0' shape=(20, 100) dtype=float32_ref>


Code:

user

Output:

<tf.Tensor 'Placeholder_3:0' shape=(1,) dtype=int32>


Code:

idx = tf.reduce_sum(tf.matmul(result,tf.transpose(tf.gather(thetau,user))),1)

idx

Output:

<tf.Tensor 'Sum_1:0' shape=(1,) dtype=float32>

标签: python-2.7tensorflow

解决方案


idx = tf.reduce_sum(tf.matmul(result,tf.transpose(tf.gather(thetau,user))),1)

给出的输出

<tf.Tensor 'Sum_1:0' shape=(1,) dtype=float32>

这告诉您这idxTensor类型的类型shape(1,),类型为Shape,告诉您基础矩阵是一维数组,1 个元素长,在一行中。


推荐阅读