Hello world in Tensorflow

First i want to tell you Tensorflow is not a library to be used as writing a hello world code, but still if you want then go ahead !

So import tensorflow library…

import tensorflow as tf

hello=tf.constant(‘Hello world’,name=’Hello’,shape=[1])


<tf.Tensor 'Hello_1:0' shape=(1,) dtype=string>

So the tensor is created it is nothing but a vector of shape 1 and type string. In order to run this tensor we need to move this tensor into a session. for this write:

with tf.Session() as sess:


 output: here b represent bytes.
[b'Hello world']
We may change the shape of tensor by defining its shape:

MultiHello=tf.constant(‘Hello world’,shape=(2,1))

and when i run this variable in session
with tf.Session() as sess:
The output will be:
[[b'Hello world']
 [b'Hello world']]

Leave a Reply