【问题标题】:tensorflow trace doesn't work张量流跟踪不起作用
【发布时间】:2016-04-19 21:08:04
【问题描述】:

我是 TensorFlow 的新手。我有一个张量 x 如下:

>>> x.eval()
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]], dtype=int32)

我想计算这个张量的迹,所以我使用tf.trace,但是它抛出了错误:

>>> tf.trace(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'trace'

我该如何解决?非常感谢

【问题讨论】:

  • 有趣。看起来像 tensorflow 中的一个错误。
  • @etarion 是的,错误是因为旧版本。我重新安装,它现在可以工作了。

标签: python tensorflow


【解决方案1】:

为我工作

import tensorflow as tf
x = tf.constant([[1, 2, 3],[4, 5, 6],[7, 8, 9]], dtype=tf.int32)
sess = tf.InteractiveSession()
x.eval()
tf.trace(x).eval()

打印出来

[[1 2 3]
 [4 5 6]
 [7 8 9]]
15

【讨论】:

  • 仍然对我不起作用。也许我使用的是旧版本?但我是在一个月前安装的。
  • 1 个月大是古代
  • 重新安装后正常,原来是旧版本的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 2018-11-20
  • 1970-01-01
  • 2017-10-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多