Why do strings returned by TensorFlow show up with a 'b' prefix in Python 3? -


i finished installing tensorflow 1.3 on rpi 3. when validating installation (according https://www.tensorflow.org/install/install_sources) somehow lowercase "b" shown up. see these codes:

root@raspberrypi:/home/pi# python python 3.4.2 (default, oct 19 2014, 13:31:11) [gcc 4.9.1] on linux type "help", "copyright", "credits" or "license" more information. >>> import tensorflow tf >>> hello = tf.constant('hello, tensorflow!') >>> sess = tf.session() >>> print(sess.run(hello)) b'hello, tensorflow!' >>> 

no, it's not bug. installation fine, normal behavior.

the b before string due tensorflow internal representation of strings.

tensorflow represents strings byte array, when "extract" them (from graph, tensorflow's internal representation, python enviroment) using sess.run(hello) bytes type , not str type.

you can verify using type function:

import tensorflow tf hello = tf.constant('hello, tensorflow!') sess = tf.session() print(type(sess.run(hello))) 

results in <class 'bytes'> whilst if do:

print(type('hello, tensorflow!')) 

results in <class 'str'>


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -