+-
评估字符串张量时,Tensorflow输出一个额外的“ b”
这个问题已经在这里有了答案:            >             What does the ‘b’ character do in front of a string literal?                                    8个
我最近在我的Conda中安装了tensorflow:
在运行以下代码时,它给了我额外的“ b”.
我不知道这个“ b”的原因..?
为什么要打印它以及如何消除它?该程序在Jupyter NoteBook中实现的Tensorflow环境中运行

import tesnorflow as tf
msg_1 = tf.constant('Welcome to TensorFlow')
with tf.Session() as s:
    print(s.sub(msg_1))

结果是

b'Welcome to TensorFlow'

See also here

最佳答案
Tensorflow将字符串表示为Bytes对象. This ‘b’ is Python’s way of marking Bytes objects.您可以通过应用.decode()将session.run()返回的Bytes对象转换为常规的python字符串:

print(s.run(msg_1).decode('UTF-8'))
点击查看更多相关文章

转载注明原文:评估字符串张量时,Tensorflow输出一个额外的“ b” - 乐贴网