Challenge - 5 Problems
Broadcasting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
TensorFlow Broadcasting Output Shape
Given the following TensorFlow code, what is the shape of the resulting tensor after the addition?
TensorFlow
import tensorflow as tf x = tf.constant([[1, 2, 3], [4, 5, 6]]) # shape (2, 3) y = tf.constant([10, 20, 30]) # shape (3,) result = x + y result_shape = result.shape
Attempts:
2 left
💡 Hint
Remember how TensorFlow broadcasts smaller tensors to match larger ones by adding dimensions.
✗ Incorrect
The tensor y with shape (3,) is broadcasted to (1, 3) and then to (2, 3) to match x. So the result shape is (2, 3).
🧠 Conceptual
intermediate2:00remaining
Understanding Broadcasting Compatibility
Which pair of tensor shapes can be broadcast together in TensorFlow without error?
Attempts:
2 left
💡 Hint
Broadcasting compares shapes from the rightmost dimension to the left.
✗ Incorrect
Shapes (4,1,3) and (3,1) align as (4,1,3) and (1,3,1) after prepending 1. Dimensions are compatible if equal or one is 1.
❓ Hyperparameter
advanced2:00remaining
Broadcasting in Tensor Operations
You have a tensor A of shape (8, 1, 6) and tensor B of shape (1, 5, 6). What will be the shape of A * B after broadcasting in TensorFlow?
Attempts:
2 left
💡 Hint
Broadcasting expands dimensions where size is 1 to match the other tensor.
✗ Incorrect
Tensor A shape (8,1,6) and B shape (1,5,6) broadcast to (8,5,6) by expanding the 1s.
🔧 Debug
advanced2:00remaining
Identifying Broadcasting Error
What error will this TensorFlow code raise due to broadcasting rules?
TensorFlow
import tensorflow as tf x = tf.constant([[1, 2], [3, 4]]) # shape (2, 2) y = tf.constant([1, 2, 3]) # shape (3,) result = x + y
Attempts:
2 left
💡 Hint
Check if the dimensions can align from right to left for broadcasting.
✗ Incorrect
Shapes (2,2) and (3,) cannot be broadcast because the last dimensions 2 and 3 differ and neither is 1.
❓ Model Choice
expert2:00remaining
Choosing Tensor Shapes for Efficient Broadcasting
You want to add two tensors efficiently in TensorFlow with minimal memory overhead. Which pair of shapes is best for broadcasting?
Attempts:
2 left
💡 Hint
Smaller dimensions with 1 allow broadcasting without copying large data.
✗ Incorrect
Option A uses many 1s allowing broadcasting with minimal memory use. Option A duplicates full shape, no broadcasting benefit.