Complete the code to import the module used for profiling NumPy operations.
import [1]
The cProfile module is used to profile Python code, including NumPy operations.
Complete the code to start profiling a function named compute_array.
profiler = cProfile.Profile() profiler.[1]('compute_array()') profiler.print_stats()
The run method runs the function under the profiler.
Fix the error in the code to measure execution time of a NumPy operation using timeit.
import numpy as np import timeit arr = np.arange(1000) time = timeit.timeit(lambda: np.[1](arr), number=1000) print(time)
The sum function correctly computes the sum of array elements. add is a ufunc needing two arrays, append is not a NumPy function, and sort is a method, not a function.
Fill both blanks to create a dictionary comprehension that profiles functions with timeit and filters results greater than 0.001 seconds.
functions = [np.sum, np.mean, np.std]
results = {func.__name__: timeit.timeit(lambda: func(np.arange(1000)), number=1000) for func in functions if [1] [2] 0.001}The comprehension measures time for each function and filters those with time greater than 0.001 seconds.
Fill all three blanks to create a profiling dictionary that stores function names, their execution times, and filters times less than 0.005 seconds.
functions = [np.min, np.max, np.median] profile = [1]: [2] for func in functions if [3] < 0.005
The dictionary comprehension keys are function names, values are execution times, and filtering is done on the execution time less than 0.005 seconds.