本文介绍了将张量的全部值打印到控制台中或写入张量流中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在控制台中打印一个大张量([32,32,3]),我只能得到这样的输出:

I need to print a large tensor ([32,32,3]) into the console, and I only get output like this:

[[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

..., 
[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]]

如何获取张量流以打印出整个张量,而不是用省略号将其截断?

How can I get tensorflow to print out the entire tensor, instead of truncating it with the ellipses?

推荐答案

从TensorFlow返回的值 Session.run() 调用是一个NumPy ndarray,因此此呈现由NumPy本身控制.一种确保所有元素均已打印的简单方法是使用 numpy.set_printoptions() :

The value returned from a TensorFlow Session.run() call is a NumPy ndarray, so this rendering is controlled by NumPy itself. One simple way to ensure that all elements are printed is to use numpy.set_printoptions():

import numpy
numpy.set_printoptions(threshold=numpy.nan)

这篇关于将张量的全部值打印到控制台中或写入张量流中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:33