gpt4 book ai didi

python - tensorflow 跟踪不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 05:32:19 25 4
gpt4 key购买 nike

我是 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'

我该如何解决?非常感谢

最佳答案

对我有用

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

关于python - tensorflow 跟踪不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36729484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com