TensorFlow Tensors and Operations 2 β Questions and Answers
Question 1: What TensorFlow dtype represents a 32-bit floating point number?
- tf.float32 (Correct answer)
- tf.float16
- tf.double
- tf.real32
Correct answer: tf.float32
tf.float32 is the standard 32-bit floating point data type used by default in most TensorFlow operations.
Question 2: How do you get the shape of a tensor as a Python tuple in TensorFlow?
- tensor.numpy().shape or tensor.shape.as_list() (Correct answer)
- tensor.get_dims()
- tensor.size()
- tf.shape_tuple(tensor)
Correct answer: tensor.numpy().shape or tensor.shape.as_list()
tensor.shape.as_list() returns the shape as a Python list, while tensor.numpy().shape gives a NumPy tuple.
Question 3: Which TensorFlow function stacks tensors along a new axis?
- tf.stack() (Correct answer)
- tf.concat()
- tf.merge()
- tf.join()
Correct answer: tf.stack()
tf.stack() creates a new dimension and stacks tensors along it, increasing rank by 1.
Question 4: What is the result of tf.constant([1,2,3]) + tf.constant([4,5,6])?
- tf.Tensor([5 7 9]) (Correct answer)
- tf.Tensor([1,2,3,4,5,6])
- tf.Tensor([4,10,18])
- Error
Correct answer: tf.Tensor([5 7 9])
TensorFlow performs element-wise addition, so each pair of corresponding elements is summed.
Question 5: Which function in TensorFlow removes dimensions of size 1?
- tf.squeeze() (Correct answer)
- tf.flatten()
- tf.reduce()
- tf.trim()
Correct answer: tf.squeeze()
tf.squeeze() removes dimensions with size 1, reducing the rank of the tensor.
Question 6: What does tf.expand_dims(tensor, axis=0) do?
- Inserts a new axis at position 0 (Correct answer)
- Removes axis 0
- Transposes axis 0
- Doubles axis 0
Correct answer: Inserts a new axis at position 0
tf.expand_dims() inserts a new dimension of size 1 at the specified axis position.
What TensorFlow dtype represents a 32-bit floating point number?