【问题标题】:Tensorflow outputs an additional 'b' when evaluating a string tensor [duplicate]在评估字符串张量时,Tensorflow 会输出一个额外的“b”[重复]
【发布时间】:2018-10-15 19:35:23
【问题描述】:

我最近在我的 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

【问题讨论】:

    标签: python tensorflow jupyter-notebook


    【解决方案1】:

    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'))
    

    【讨论】:

    • 谢谢,它解决了我的问题 :)
    猜你喜欢
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 2014-01-28
    • 2018-08-22
    相关资源
    最近更新 更多