0
0
TensorFlowml~20 mins

Tensor math operations in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tensor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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())
A
[[6 8]
 [10 12]]
B
[[4 8]
 [10 12]]
C
[[6 8]
 [11 12]]
D
[[5 7]
 [10 12]]
Attempts:
2 left
💡 Hint
tf.add adds corresponding elements of two tensors.
Model Choice
intermediate
1: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?
Atf.matmul
Btf.multiply
Ctf.add
Dtf.reduce_sum
Attempts:
2 left
💡 Hint
Think about the operation that multiplies elements one by one.
Hyperparameter
advanced
1: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)?
Aaxis=0
Baxis=1
Caxis=None
Daxis=2
Attempts:
2 left
💡 Hint
Reducing over an axis removes that dimension.
🔧 Debug
advanced
2: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())
A'a' and 'b' have different data types
Btf.add cannot add tensors with more than one dimension
CShapes of 'a' and 'b' are incompatible for broadcasting
DTensorFlow requires explicit reshaping before addition
Attempts:
2 left
💡 Hint
Check the shapes of the tensors and how broadcasting works.
🧠 Conceptual
expert
1: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]?
A(3, 2, 4)
B(4, 3, 2)
C(2, 4, 3)
D(3, 4, 2)
Attempts:
2 left
💡 Hint
tf.transpose permutes the dimensions according to the perm list.