How to do it...

To implement the first operational gate, , in TensorFlow and train the output towards the value of 50, follow these steps:

  1. Start off by loading TensorFlow and creating a graph session as follows:
import tensorflow as tf 
sess = tf.Session() 
  1. Now we will need to declare our model variable, input data, and placeholder. We make our input data equal to the value 5, so that the multiplication factor to get 50 will be 10 (that is, 5X10=50), as follows:
a = tf.Variable(tf.constant(4.))x_val = 5.x_data = tf.placeholder(dtype=tf.float32)
  1. Next, we add the operation to our computational graph with the following input:
multiplication ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.