tensorflow: 查看 tensor详细数值方法

作者:JNingWei 时间:2022-07-24 09:40:37 

问题

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


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

输出:


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

原因:

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

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

解决方法

法一:


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

输出:


1

法二:


import tensorflow as tf
x = tf.constant(1)
sess = tf.InteractiveSession()
print x.eval()

输出:


1

来源:https://blog.csdn.net/JNingWei/article/details/73557938

标签:tensorflow,tensor,数值
0
投稿

猜你喜欢

  • 在mac下查找python包存放路径site-packages的实现方法

    2023-06-12 21:12:36
  • 利用python实现PSO算法优化二元函数

    2022-06-17 20:53:04
  • python 创建一个空dataframe 然后添加行数据的实例

    2022-05-08 01:51:59
  • 利用XSLT把ADO记录集转换成XML

    2008-09-05 17:12:00
  • 在python中使用xlrd获取合并单元格的方法

    2023-09-09 17:00:43
  • python中split(), os.path.split()和os.path.splitext()的用法

    2022-03-23 09:06:40
  • Python中函数及默认参数的定义与调用操作实例分析

    2022-01-15 05:16:31
  • 设置mysql最大连接数的方法

    2010-12-03 16:00:00
  • 实例讲解启动mysql server失败的解决方法

    2008-12-26 17:27:00
  • Python面向对象之继承和多态用法分析

    2023-01-02 02:55:16
  • 蜕变——记QQ医生3.0

    2009-09-16 14:41:00
  • 教你如何使用Conda命令 + 安装tensorflow

    2021-09-17 22:32:07
  • 浅谈django框架集成swagger以及自定义参数问题

    2022-01-09 20:25:10
  • 教你如何使用Python selenium

    2022-05-15 11:13:50
  • Python集合的增删改查操作

    2023-09-30 00:48:18
  • 详解python中的数据类型和控制流

    2022-08-11 14:32:50
  • Ewebeditor及fckeditork单引号的问题

    2010-04-05 21:12:00
  • python3实现弹弹球小游戏

    2021-04-21 07:12:56
  • Oracle row_number() over()解析函数高效实现分页

    2011-12-01 10:33:07
  • php快递单号查询接口使用示例

    2023-10-25 07:39:55
  • asp之家 网络编程 m.aspxhome.com