0
0
TensorFlowml~10 mins

Why tensors are the fundamental data unit in TensorFlow - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 2D tensor with TensorFlow.

TensorFlow
import tensorflow as tf

matrix = tf.constant([1])
print(matrix)
Drag options to blanks, or click blank then click option'
A[[1, 2], [3, 4]]
B[1, 2, 3, 4]
C1, 2, 3, 4
Dtf.constant([1, 2, 3, 4])
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a flat list instead of a nested list for a 2D tensor.
Using commas without brackets which causes syntax errors.
2fill in blank
medium

Complete the code to get the shape of a tensor.

TensorFlow
import tensorflow as tf

tensor = tf.constant([[1, 2], [3, 4], [5, 6]])
shape = tensor.[1]
print(shape)
Drag options to blanks, or click blank then click option'
Asize
Bndim
Crank
Dshape
Attempts:
3 left
💡 Hint
Common Mistakes
Using size which returns total elements, not shape.
Using rank which returns the number of dimensions.
3fill in blank
hard

Fix the error in the code to multiply two tensors element-wise.

TensorFlow
import tensorflow as tf

a = tf.constant([1, 2, 3])
b = tf.constant([4, 5, 6])
result = a [1] b
print(result)
Drag options to blanks, or click blank then click option'
A*
B@
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ performs matrix multiplication (dot product) instead of element-wise.
Using + or - changes the operation to addition or subtraction.
4fill in blank
hard

Fill both blanks to create a tensor of zeros with shape (3, 4) and type float32.

TensorFlow
import tensorflow as tf

zeros_tensor = tf.[1](shape=[2], dtype=tf.float32)
print(zeros_tensor)
Drag options to blanks, or click blank then click option'
Azeros
Bones
C(3, 4)
D[3, 4]
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.ones instead of tf.zeros.
Using a list for shape instead of a tuple.
5fill in blank
hard

Fill all three blanks to create a tensor from a list, reshape it to (2, 3), and print its new shape.

TensorFlow
import tensorflow as tf

list_data = [1, 2, 3, 4, 5, 6]
tensor = tf.constant([1])
reshaped = tf.reshape(tensor, [2])
print(reshaped.[3])
Drag options to blanks, or click blank then click option'
Alist_data
B[2, 3]
Cshape
D(2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for reshape shape.
Trying to call reshaped.shape() (it's a property, not a method).