如何解决tensorflow打印tensor有省略号的问题

2023-05-19,

这篇文章给大家分享的是有关如何解决tensorflow打印tensor有省略号的问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

先上代码:

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有省略号的问题”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

《如何解决tensorflow打印tensor有省略号的问题.doc》

下载本文的Word格式文档,以方便收藏与打印。