Challenge - 5 Problems
Tensor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this TensorFlow code?
Consider the following code snippet using TensorFlow. What will be the printed output?
TensorFlow
import tensorflow as tf a = tf.constant([[1, 2], [3, 4]]) b = tf.constant([[5, 6], [7, 8]]) c = tf.add(a, b) print(c.numpy())
Attempts:
2 left
💡 Hint
tf.add adds corresponding elements of two tensors.
✗ Incorrect
The tf.add function adds each element of tensor 'a' to the corresponding element of tensor 'b'. So 1+5=6, 2+6=8, 3+7=10, 4+8=12.
❓ Model Choice
intermediate1:30remaining
Which TensorFlow operation computes the element-wise product of two tensors?
You want to multiply two tensors element by element in TensorFlow. Which operation should you use?
Attempts:
2 left
💡 Hint
Think about the operation that multiplies elements one by one.
✗ Incorrect
tf.multiply performs element-wise multiplication, multiplying each element of one tensor by the corresponding element of the other tensor.
❓ Hyperparameter
advanced1:30remaining
Choosing the correct axis for tf.reduce_sum
Given a tensor of shape (3, 4, 5), which axis should you reduce over to get a tensor of shape (3, 4)?
Attempts:
2 left
💡 Hint
Reducing over an axis removes that dimension.
✗ Incorrect
Reducing over axis=2 (the last dimension of size 5) sums across that dimension, resulting in shape (3, 4).
🔧 Debug
advanced2:00remaining
Why does this TensorFlow code raise an error?
Examine the code below. Why does it raise an error?
TensorFlow
import tensorflow as tf a = tf.constant([1, 2, 3]) b = tf.constant([[1, 2], [3, 4], [5, 6]]) c = tf.add(a, b) print(c.numpy())
Attempts:
2 left
💡 Hint
Check the shapes of the tensors and how broadcasting works.
✗ Incorrect
Tensor 'a' has shape (3,) and 'b' has shape (3,2). TensorFlow tries to broadcast but the shapes are incompatible because the first dimension of 'a' is missing.
🧠 Conceptual
expert1:30remaining
What is the effect of tf.transpose on a 3D tensor?
You have a tensor of shape (2, 3, 4). What will be the shape after applying tf.transpose with perm=[1, 0, 2]?
Attempts:
2 left
💡 Hint
tf.transpose permutes the dimensions according to the perm list.
✗ Incorrect
The perm argument [1, 0, 2] swaps the first and second dimensions, so shape (2,3,4) becomes (3,2,4).