Challenge - 5 Problems
Tensor Creation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output shape of this tensor?
Given the following TensorFlow code, what is the shape of the tensor
t?TensorFlow
import tensorflow as tf t = tf.constant([[1, 2, 3], [4, 5, 6]]) shape = t.shape
Attempts:
2 left
💡 Hint
Think about how many rows and columns the list has.
✗ Incorrect
The tensor is created from a list of two lists, each with three elements, so the shape is (2, 3).
❓ Model Choice
intermediate1:30remaining
Which tensor creation method creates a mutable tensor?
In TensorFlow, which method creates a tensor whose values can be changed after creation?
Attempts:
2 left
💡 Hint
Mutable means you can change the values after creation.
✗ Incorrect
tf.Variable creates a tensor that can be updated, unlike tf.constant, tf.zeros, or tf.ones which create immutable tensors.
❓ Predict Output
advanced2:00remaining
What is the output of this code?
What does the following TensorFlow code print?
TensorFlow
import tensorflow as tf x = tf.zeros(shape=(2, 3), dtype=tf.int32) print(x.numpy())
Attempts:
2 left
💡 Hint
Check the dtype and the function used to create the tensor.
✗ Incorrect
tf.zeros creates a tensor filled with zeros. dtype=tf.int32 means integers, so zeros are printed without decimals.
❓ Hyperparameter
advanced1:30remaining
Which argument changes the data type of a tensor?
When creating a tensor with tf.ones(), which argument sets the data type of the tensor elements?
Attempts:
2 left
💡 Hint
This argument controls if the tensor holds integers, floats, or other types.
✗ Incorrect
The dtype argument specifies the data type of the tensor elements.
🔧 Debug
expert2:00remaining
Why does this code raise an error?
Examine the code below. Why does it raise an error?
TensorFlow
import tensorflow as tf v = tf.Variable(tf.constant([1, 2, 3])) v.assign([4, 5])
Attempts:
2 left
💡 Hint
Check the shapes of the original variable and the new value.
✗ Incorrect
The assign method requires the new value to have the same shape as the variable. Here, the original variable has shape (3,), but the new value has shape (2,), causing a shape mismatch error.