【问题标题】:Understanding shape=(1,) tensor理解 shape=(1,) 张量
【发布时间】:2018-07-12 04:13:08
【问题描述】:

我有一个张量“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>

【问题讨论】:

  • 已经有很好的讨论here

标签: python-2.7 tensorflow


【解决方案1】:
idx = tf.reduce_sum(tf.matmul(result,tf.transpose(tf.gather(thetau,user))),1)

输出

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

这告诉你idxshape(1,) 类型shape(1,) 的类型Shape,告诉你你的底层矩阵是一个一维数组,1 个元素长,在一排。

【讨论】:

  • 截至本文发布时,API 为 v1.9,可在:tensorflow.org/api_docs 获取。你可能想使用 python api,虽然我没有检查它是否需要 python2.7 或 python3。
猜你喜欢
  • 2020-02-11
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
  • 2022-07-04
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
  • 2018-10-02
相关资源
最近更新 更多