TensorFlow Tensors and Operations 1 — Questions and Answers
Question 1: What is the rank of a scalar tensor in TensorFlow?
- 0 (Correct answer)
- 1
- 2
- 3
Correct answer: 0
A scalar is a rank-0 tensor because it has no axes.
Question 2: Which TensorFlow function creates a tensor filled with zeros?
- tf.zeros() (Correct answer)
- tf.empty()
- tf.null()
- tf.blank()
Correct answer: tf.zeros()
tf.zeros() creates a tensor of the specified shape with all elements set to 0.
Question 3: What does tf.cast() do in TensorFlow?
- Changes a tensor's data type (Correct answer)
- Reshapes a tensor
- Transposes a tensor
- Splits a tensor
Correct answer: Changes a tensor's data type
tf.cast() converts a tensor from one data type to another, such as from float32 to int32.
Question 4: Which attribute gives you the number of elements in a TensorFlow tensor?
- tf.size() (Correct answer)
- tf.count()
- tf.length()
- tf.total()
Correct answer: tf.size()
tf.size() returns the total number of elements across all dimensions of a tensor.
Question 5: What does tf.reshape() require to be consistent?
- Total number of elements (Correct answer)
- Data type
- Rank
- Device placement
Correct answer: Total number of elements
tf.reshape() requires the total number of elements in the new shape to match the original tensor.
Question 6: Which operation performs element-wise multiplication in TensorFlow?
- tf.multiply() (Correct answer)
- tf.matmul()
- tf.dot()
- tf.cross()
Correct answer: tf.multiply()
tf.multiply() performs element-wise (Hadamard) multiplication between two tensors.
What is the rank of a scalar tensor in TensorFlow?