Appendix

1. Introduction to Machine Learning with TensorFlow

Activity 1.01: Performing Tensor Addition in TensorFlow

Solution:

  1. Import the TensorFlow library:

    import tensorflow as tf

  2. Create two tensors with a rank 0 using TensorFlow's Variable class:

    var1 = tf.Variable(2706, tf.int32)

    var2 = tf.Variable(2386, tf.int32)

  3. 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 at Location X.

  4. Create two tensors, a scalar of rank 0 and a vector of rank 1, using TensorFlow's Variable class:

    scalar1 = tf.Variable(95, tf.int32)

    vector1 = tf.Variable([2706, 2799, 5102], \

                          tf.int32)

  5. Create ...

Get The TensorFlow Workshop 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.