Complete the code to install TensorFlow using pip.
pip install [1]To install TensorFlow, you use pip install tensorflow. This command downloads and installs the TensorFlow package.
Complete the code to check if TensorFlow can access a GPU device.
import tensorflow as tf print(tf.config.list_physical_devices('[1]'))
To check for GPU devices, you use tf.config.list_physical_devices('GPU'). This lists all GPUs TensorFlow can use.
Fix the error in the code to enable memory growth for the first GPU device.
gpus = tf.config.list_physical_devices('GPU') if gpus: try: tf.config.experimental.[1](gpus[0], True) except RuntimeError as e: print(e)
The correct function to enable memory growth on a GPU device is set_memory_growth from tf.config.experimental.
Fill both blanks to import TensorFlow and print the TensorFlow version.
import [1] as tf print(tf.[2].VERSION)
You import TensorFlow as tf and access the version with tf.version.VERSION.
Fill all three blanks to list GPU physical devices and print their names.
devices = tf.config.list_physical_devices([1]) for device in devices: print(device.[2]) # Check if any device is a GPU has_gpu = any(device.device_type == [3] for device in devices) print('GPU available:', has_gpu)
To list GPU devices, use tf.config.list_physical_devices('GPU'). Each device has a name attribute. To check device type, compare with the string 'GPU'.