0
0
NumPydata~10 mins

Monitoring memory usage in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the module used for monitoring memory usage.

NumPy
import [1]
Drag options to blanks, or click blank then click option'
Apsutil
Bos
Csys
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'os' which does not provide detailed memory info.
Using 'sys' which is for system-specific parameters.
2fill in blank
medium

Complete the code to get the current process memory usage in bytes.

NumPy
process = psutil.Process()
memory_info = process.[1]()
Drag options to blanks, or click blank then click option'
Amemory_info_ex
Bmemory_full_info
Cmemory_info
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'memory_full_info' which may not be available on all platforms.
3fill in blank
hard

Fix the error in the code to print the resident set size (RSS) memory in MB.

NumPy
print(f"Memory usage: {memory_info.[1] / (1024 * 1024):.2f} MB")
Drag options to blanks, or click blank then click option'
Avms
Brss
Cuss
Dshared
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'vms' which is virtual memory size, not physical.
Using 'uss' which is unique set size and may not be available everywhere.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps array names to their memory usage in bytes.

NumPy
memory_usage = {name: arr.[1] * arr.[2] for name, arr in arrays.items()}
Drag options to blanks, or click blank then click option'
Anbytes
Bitemsize
Csize
Dshape
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nbytes' which already gives total bytes, so multiplying again causes error.
Using 'shape' which is a tuple, not a number.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that filters arrays with memory usage greater than 1MB.

NumPy
large_arrays = {name: arr for name, arr in arrays.items() if arr.[1] * arr.[2] [3] 1024 * 1024}
Drag options to blanks, or click blank then click option'
Asize
Bitemsize
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which would select smaller arrays.
Using 'nbytes' instead of size and itemsize multiplication.