Hello Word! – Tensor flow


Hello folks,

Today’s blog will be short and sweet. You will learn how to print Hello World, yes a very basic Hello world in our favorite TensorFlow library. So without wasting any time let’s get started.

First, let’s import TensorFlow in Google colab or Jupyter notebook.

import tensorflow as tf

Now we will create two constants ‘a’ and ‘b’ and assign ‘hello’ and ‘ world!’ strings to respective variables. To execute a + b we will take the third variable ‘c’, and assign a + b to ‘c’. Now to execute all these processes we will require to take the help of the Session. According to the official TensorFlow document, A Session object encapsulates the environment in which Operation objects are executed, and Tensor objects are evaluated. Now let’s check the code.

with tf.compat.v1.Session() as sess:
  a = tf.constant("hello")
  b = tf.constant(" world!")
  c = a + b
  print(sess.run(c))

Now let’s see the output,

b'hello world!'

So Yes, you did it! you wrote your first code in TensorFlow! Hope the content is usefull to you.

Thank you for reading 🙂

Happy coding 🙂

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started