0
0
TensorFlowml~20 mins

Tensor creation (constant, variable, zeros, ones) in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tensor Creation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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
A(6,)
B(3, 2)
C(2, 3)
D(1, 6)
Attempts:
2 left
💡 Hint
Think about how many rows and columns the list has.
Model Choice
intermediate
1:30remaining
Which tensor creation method creates a mutable tensor?
In TensorFlow, which method creates a tensor whose values can be changed after creation?
Atf.Variable()
Btf.zeros()
Ctf.constant()
Dtf.ones()
Attempts:
2 left
💡 Hint
Mutable means you can change the values after creation.
Predict Output
advanced
2: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())
A
[[1 1 1]
 [1 1 1]]
B
[[0. 0. 0.]
 [0. 0. 0.]]
C
[[1. 1. 1.]
 [1. 1. 1.]]
D
[[0 0 0]
 [0 0 0]]
Attempts:
2 left
💡 Hint
Check the dtype and the function used to create the tensor.
Hyperparameter
advanced
1: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?
Adtype
Bsize
Cvalue
Dshape
Attempts:
2 left
💡 Hint
This argument controls if the tensor holds integers, floats, or other types.
🔧 Debug
expert
2: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])
Atf.Variable cannot be created from tf.constant.
BThe assign method requires the new value to have the same shape as the variable.
CThe list passed to assign must be a tensor, not a Python list.
DThe variable v is immutable and cannot be assigned new values.
Attempts:
2 left
💡 Hint
Check the shapes of the original variable and the new value.