gpt4 book ai didi

tensorflow: 查看 tensor详细数值方法

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 30 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章tensorflow: 查看 tensor详细数值方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

问题 。

tensor详细数值 不能直接print打印:

?
1
2
3
import tensorflow as tf
x = tf.constant( 1 )
print x

输出:

?
1
Tensor( "Const:0" , shape = (), dtype = int32)

原因:

print只能打印输出shape的信息,而要打印输出tensor的值,需要借助 tf.Session,tf.InteractiveSession.

因为我们在建立graph的时候,只建立 tensor 的 结构形状信息 ,并没有 执行 数据的操作.

解决方法 。

法一:

?
1
2
3
4
import tensorflow as tf
x = tf.constant( 1 )
with tf.Session() as sess:
  print sess.run(x)

输出:

?
1
1

法二:

?
1
2
3
4
import tensorflow as tf
x = tf.constant( 1 )
sess = tf.InteractiveSession()
print x. eval ()

输出:

?
1
1

以上这篇tensorflow: 查看 tensor详细数值方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.

原文链接:https://blog.csdn.net/JNingWei/article/details/73557938 。

最后此篇关于tensorflow: 查看 tensor详细数值方法的文章就讲到这里了,如果你想了解更多关于tensorflow: 查看 tensor详细数值方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

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