Now, we will explore some of the operations in TensorFlow using the eager execution mode:
x = tf.constant([1., 2., 3.])
y = tf.constant([3., 2., 1.])
Let's start with some basic arithmetic operations.
Use tf.add to add two numbers:
sum = tf.add(x,y)
sum.numpy()
array([4., 4., 4.], dtype=float32)
The tf.subtract function is used for finding the difference between two numbers:
difference = tf.subtract(x,y)
difference.numpy()
array([-2., 0., 2.], dtype=float32)
The tf.multiply function is used for multiplying two numbers:
product = tf.multiply(x,y)
product.numpy()
array([3., 4., 3.], dtype=float32)
Divide two numbers using tf.divide:
division = tf.divide(x,y)
division.numpy()
array([0.33333334, 1. , 3. ], dtype=float32)
The dot product can be computed as follows:
dot_product = tf.reduce_sum(tf.multiply(x, y))
dot_product.numpy()
10.0
Next,...