为什么tf.Print()不以十为单位打印

2024-04-20 13:20:26 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码不会给出任何错误,但也不会打印张量。

import tensorflow as tf
import numpy as np

# Some tensor we want to print the value of
x = tf.placeholder(tf.float32, shape=[2, 2, 2])
a = np.array([[[1.,1.], [1.,1.]], [[2.,2.], [2.,2.]]])

m = tf.Print(x,[x])

with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    m_eval = m.eval(session=sess,feed_dict={x: a})

编辑:在bgshi回复之后,我发现在iPython控制台中,代码确实打印了张量值。但我用的是iPython笔记本。有办法把它显示在笔记本上吗?


Tags: 代码importnumpytftensorflowas错误ipython
1条回答
网友
1楼 · 发布于 2024-04-20 13:20:26

从文档中:

This op prints to the standard error. It is not currently compatible with jupyter notebook (printing to the notebook server's output, not into the notebook)

tf.print documentation

相关问题 更多 >