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 multidimensional 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 be able to perform the basic numerical operations between tensors and array operations. Before 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
Moreover, please run the following commands:
X <- tf$constant(matrix(c(as.integer(rnorm(200, mean = 10, sd = 2)), as.integer(rnorm(200, mean = 50, sd = 10))), nrow = 200, ncol = 2))
a <- tf$constant(matrix(c(3, 12), nrow = 1, ncol = 2), dtype = tf$float32, name = "a")
b <- tf$constant(matrix(c(5, 15), nrow = 1, ncol = 2), dtype = tf$float32, name = "b")
weights <- tf$constant(matrix(c(0.015, 0.02, 0.025, 0.03), nrow = 2, ncol = 2), dtype = tf$float32, name = "weights")
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.
Print out the value of the tensor
Add the two tensors
Subtract the two tensors
Divide the two tensors
Conduct element-wise multiplication between the two tensors
Conduct a matrix multiplication between the tensors
Hint: You need to transpose
Calculate the inner product of
weights. Then add the
bias. Assign this calculation to the object
Print out the shape of
Split the tensor X into
The dimensions should be:
train_X – (160, 2)
validation_X – (20, 2)
test_X – (20, 2)
Print out the dimensions of the splits to make sure you got it right.
Concatenate the tensors
test_x,assign it to the object
Print out the dimensions of the concatenated tensor to make sure you got it right.