如何处理TensorFlow中打印Tensor时出现的省略号问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计321个文字,预计阅读时间需要2分钟。
在先代代码中,我们使用了TensorFlow库来创建两个张量,并使用一个会话来运行这些操作。以下是简化后的代码,不包含注释和多余的字符,确保不超过100个字:
pythonimport tensorflow as tfx=tf.ones([100, 200], dtype=tf.int32, name='x')y=tf.zeros([2, 3], dtype=tf.float32, name='y')with tf.Session() as sess: print(sess.run([x, y]))
先上代码:
import tensorflow as tf x = tf.ones(shape=[100, 200], dtype=tf.int32, name='x') y = tf.zeros(shape=[2, 3], dtype=tf.float32, name='y') with tf.Session() as sess: print(sess.run([x, y]))
输出结果如下:
如果我调试的时候想查看省略号代表的值是什么
只需要改成如下代码就行:
import tensorflow as tf import numpy as np #借助numpy模块的set_printoptions()函数,将打印上限设置为无限即可 np.set_printoptions(threshold=np.inf) x = tf.ones(shape=[10, 20], dtype=tf.int32, name='x') y = tf.zeros(shape=[2, 3], dtype=tf.float32, name='y') with tf.Session() as sess: print(sess.run(x, y))
输出结果如下:可以看到省略号的部分也都打出来了
以上这篇解决tensorflow打印tensor有省略号的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。
本文共计321个文字,预计阅读时间需要2分钟。
在先代代码中,我们使用了TensorFlow库来创建两个张量,并使用一个会话来运行这些操作。以下是简化后的代码,不包含注释和多余的字符,确保不超过100个字:
pythonimport tensorflow as tfx=tf.ones([100, 200], dtype=tf.int32, name='x')y=tf.zeros([2, 3], dtype=tf.float32, name='y')with tf.Session() as sess: print(sess.run([x, y]))
先上代码:
import tensorflow as tf x = tf.ones(shape=[100, 200], dtype=tf.int32, name='x') y = tf.zeros(shape=[2, 3], dtype=tf.float32, name='y') with tf.Session() as sess: print(sess.run([x, y]))
输出结果如下:
如果我调试的时候想查看省略号代表的值是什么
只需要改成如下代码就行:
import tensorflow as tf import numpy as np #借助numpy模块的set_printoptions()函数,将打印上限设置为无限即可 np.set_printoptions(threshold=np.inf) x = tf.ones(shape=[10, 20], dtype=tf.int32, name='x') y = tf.zeros(shape=[2, 3], dtype=tf.float32, name='y') with tf.Session() as sess: print(sess.run(x, y))
输出结果如下:可以看到省略号的部分也都打出来了
以上这篇解决tensorflow打印tensor有省略号的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

