Complete the code to enable eager execution in TensorFlow.
import tensorflow as tf tf.config.run_functions_eagerly([1])
Setting run_functions_eagerly(True) enables eager execution mode in TensorFlow, which runs operations immediately.
Complete the code to create a TensorFlow function that runs as a graph.
import tensorflow as tf @tf.function def add(a, b): return a [1] b
The @tf.function decorator compiles the function into a graph. The function adds two tensors using the + operator.
Fix the error in the code to print the result of a TensorFlow tensor in eager mode.
import tensorflow as tf a = tf.constant(5) print([1])
eval() which requires a session in graph mode.value() or data().In eager mode, use tensor.numpy() to get the value as a NumPy array for printing.
Fill both blanks to create a TensorFlow graph function that multiplies and then adds two tensors.
import tensorflow as tf @tf.function def compute(x, y): mul = x [1] y return mul [2] y
The function multiplies x and y first, then adds y to the result.
Fill all three blanks to create a TensorFlow function that subtracts, divides, and then multiplies two tensors.
import tensorflow as tf @tf.function def complex_op(a, b): sub = a [1] b div = sub [2] b return div [3] a
The function subtracts b from a, divides the result by b, then multiplies by a.