2017-09-14 36 views
1

我剛剛在RPi 3上完成安裝Tensorflow 1.3。驗證安裝(根據此https://www.tensorflow.org/install/install_sources)以某種方式顯示小寫「b」。看到這些代碼:爲什麼TensorFlow返回的字符串在Python 3中顯示爲'b'前綴?

[email protected]:/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" for more information. 
>>> import tensorflow as tf 
>>> hello = tf.constant('Hello, TensorFlow!') 
>>> sess = tf.Session() 
>>> print(sess.run(hello)) 
b'Hello, TensorFlow!' 
>>> 

回答

2

不,這不是一個錯誤。你的安裝非常好,這是正常的行爲。

b之前的字符串是由於Tensorflow內部表示形式的字符串。

Tensorflow表示字符串作爲字節數組,從而當你「提取物」它們(從曲線圖,從而tensorflow的內部表示,以蟒環境)使用sess.run(hello)你得到一個bytes類型,而不是一個str類型。而如果你做

import tensorflow as tf 
hello = tf.constant('Hello, TensorFlow!') 
sess = tf.Session() 
print(type(sess.run(hello))) 

結果<class 'bytes'>

您可以在此使用type功能驗證

print(type('Hello, TensorFlow!')) 

結果<class 'str'>

+0

我很高興,謝謝! – user1801605

+0

不客氣!如果解決了您的問題,請記得接受我的回覆。 – nessuno

相關問題