Complete the code to import the module used for monitoring memory usage.
import [1]
The psutil module provides functions to monitor system resources like memory usage.
Complete the code to get the current process memory usage in bytes.
process = psutil.Process()
memory_info = process.[1]()The memory_info() method returns memory usage details of the current process.
Fix the error in the code to print the resident set size (RSS) memory in MB.
print(f"Memory usage: {memory_info.[1] / (1024 * 1024):.2f} MB")
The rss attribute gives the resident set size, which is the non-swapped physical memory used by the process.
Fill both blanks to create a dictionary comprehension that maps array names to their memory usage in bytes.
memory_usage = {name: arr.[1] * arr.[2] for name, arr in arrays.items()}The total memory used by a NumPy array is size * itemsize, where size is the number of elements and itemsize is the bytes per element.
Fill all three blanks to create a dictionary comprehension that filters arrays with memory usage greater than 1MB.
large_arrays = {name: arr for name, arr in arrays.items() if arr.[1] * arr.[2] [3] 1024 * 1024}This comprehension selects arrays where size * itemsize is greater than 1MB (1024 * 1024 bytes).