Data Manipulation - d2l.ai Exercises - Part 1
The first notebook in a series to be posted aiming to solve and understand exercises from d2l.ai curriculum on deep learning
This is the first notebook in a series to be posted aiming to solve and understand exercises from d2l.ai curriculum on deep learning, the corresponding lesson reference for this notebook is this link.
This series of practice notebook posts may use the exercises and content provided from d2l.ai, I write these to get a good hands-on practice in deep learning.
import tensorflow as tf
tf.__version__
X = tf.reshape(tf.range(12, dtype=tf.float32), (3, 4))
Y = tf.constant([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
X, Y
a = tf.reshape(tf.range(3), (3, 1))
b = tf.reshape(tf.range(2), (1, 2))
a, b
X == Y
X < Y
X > Y
The operations are as expected of an elementwise comparison. Let's try to check if the operations are opposites of each other by trying to not
one of them.
(X > Y) == tf.math.logical_not(X < Y)
We can see that apart from two cases where the numbers were equal(1 and 3), all the other values matched
a = tf.reshape(tf.range(16), (2, 4, -1))
b = tf.reshape(tf.range(16), (4, 2, -1))
a, b
a + b
I tried using tensors of 3d shapes, thinking it might but it did'nt, so I was searching about the rules to determine whether an array can be broadcasted or not and found this documentation, where the conditions are explained, the main points to consider broadcasting are, if the dimensions
are equal, or
one of them is 1
In the above case we hade shapes: [2,4,2]
vs. [4,2,2]
, Let's try a different shape
a = tf.reshape(tf.range(12), (6, 2, -1))
b = tf.reshape(tf.range(16), (1, -1))
a, b
a + b
Similar to the examples in the link, the above example followed the rules and operation(addition) could happen with the help of broadcasting.
a - 6 X 2 X 1
b - 1 X 16
a + b - 6 X 2 X 16