1. Introduction to Machine Learning with TensorFlow
Activity 1.01: Performing Tensor Addition in TensorFlow
Solution:
- Import the TensorFlow library:
import tensorflow as tf
- Create two tensors with a rank
0
using TensorFlow'sVariable
class:var1 = tf.Variable(2706, tf.int32) var2 = tf.Variable(2386, tf.int32)
- Create a new variable to add the two scalars created and print the result:
var_sum = var1 + var2 var_sum.numpy()
This will result in the following output:
5092
This output shows the total revenue for
Product A
atLocation X
. - Create two tensors, a scalar of rank
0
and a vector of rank1
, using TensorFlow'sVariable
class:scalar1 = tf.Variable(95, tf.int32) vector1 = tf.Variable([2706, 2799, 5102], \ tf.int32)
- Create a new variable as the sum of the scalar and vector created and print the result:
vector_scalar_sum...