TensorFlow and tf.assign () variables with string

I'm new to tensorflow, here is a quick question, this is my code

session=tf.Session()
x=tf.Variable(str)
valueOfX=session.run(x.assign('xyz'))
print(valueOfX)

      

Why output =>

b'xyz

But when I use int as data type and assign an integer, the assignment is ok.

+3


source to share


1 answer


This confusion arises from the fact that Python 3 uses the Unicode string representation for string literals. A printable representation b'xyz'

means that valueOfX

is a bytes

object
. TensorFlow uses strings bytes

as an internal representation of all tensors and variables, and (when using Python 3) implicitly converts str

literals such as 'xyz'

in your code bytes

to using Unicode UTF-8 encoding.



+2


source







All Articles