Tensorflow is an open source, software library for numerical computation using **data flow graphs**. Nodes in the graph are called ops (short for operations), while the graph edges represent the R multi-dimensional data arrays (tensors) communicated between them. An op takes zero or more Tensors, performs some computation, and produces zero or more Tensors.

In this set of exercises, we will go through the basics of Tensorflow. By the end of this post, you will have a good understanding on variable tensor types. Before we start solving the exercises, it is recommended to check out the tutorial that this post is based on.

Before proceeding, it might be helpful to look over the help pages for the `tf$Variable`

, `tf$ones`

, `tf$zeros`

, `tf$global_variables_initializer`

, `tf$variables_initializer`

, `tf$train$Saver`

, `saver$save`

, `saver$restore`

, `tf$assign`

.

Answers to the exercises are available here. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.

Exercise 1

Create a variable `W`

of shape 10 x 10, filled with ones and a variable `b`

of shape 10 X 1, filled with zeros.

Exercise 2

Initialize all the variables you have created before.

Exercise 3

Initialize only the variable `W`

.

Exercise 4

Create a variable `W_dec`

with ten times the value of `W`

.

Exercise 5

Print the structure of the variable.

Exercise 6

Print the values of the variable.

Exercise 7

Save the variable `b`

to a directory of your choice and name the file as ‘save.ckpt’.

Exercise 8

Restore the variable you have saved on the previous exercise.

Exercise 9

Create a Variable named “current_state” that will be initialized to the scalar value 0. Then, create a constant named ‘five’ and with the value 5. After that, create another object named ‘new_value’ that is the addition of ‘current_state’ and ‘five’ (use `tf$add`

). Having done that, create a new object that you assign the ‘new_value’ to ‘current_state’.

Exercise 10

Initialize the variable. Then, create a for loop with 5 steps where you assign the new value to the current state. Anything interesting you have noticed?

**What's next:**

- Explore all our (>1000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

## Leave a Reply