0
0
NumPydata~5 mins

Memory-mapped arrays for large data in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a memory-mapped array in NumPy?
A memory-mapped array is a way to access large data stored on disk as if it were in memory, without loading the entire data into RAM. It allows working with data too big to fit in memory by loading only needed parts.
Click to reveal answer
beginner
How do you create a memory-mapped array in NumPy?
Use numpy.memmap(filename, dtype, mode, shape) to create a memory-mapped array. It links the array to a file on disk, specifying data type, access mode, and shape.
Click to reveal answer
beginner
Why use memory-mapped arrays instead of loading the whole file into memory?
Memory-mapped arrays let you work with files larger than your RAM by loading only parts you need. This saves memory and speeds up processing for big data.
Click to reveal answer
intermediate
What does the mode parameter in numpy.memmap control?
The mode controls how the file is opened: 'r' for read-only, 'r+' for read-write, 'w+' to create or overwrite, and 'c' for copy-on-write.
Click to reveal answer
intermediate
Can you modify data in a memory-mapped array?
Yes, if you open the memory-mapped array in a write mode like 'r+' or 'w+', you can change data and it will be saved back to the file on disk.
Click to reveal answer
What is the main advantage of using a memory-mapped array?
AIt speeds up CPU calculations by using GPU
BIt allows working with data larger than RAM by loading parts on demand
CIt automatically cleans data errors
DIt compresses data to save disk space
Which NumPy function creates a memory-mapped array?
Anumpy.memmap()
Bnumpy.loadtxt()
Cnumpy.array()
Dnumpy.fromfile()
If you want to modify a memory-mapped array and save changes, which mode should you use?
A'r+'
B'c'
C'r'
D'r--'
What happens if you open a memory-mapped array with mode 'c'?
AOverwrite the file
BRead-only access
CCopy-on-write, changes not saved to disk
DAppend data to the file
Which of these is NOT a benefit of memory-mapped arrays?
AHandling files larger than RAM
BSaving memory by loading data on demand
CFaster access to small parts of large files
DAutomatic data cleaning
Explain how memory-mapped arrays help when working with very large datasets.
Think about how you might read a huge book by opening only the pages you need.
You got /3 concepts.
    Describe the steps to create and use a memory-mapped array in NumPy.
    Remember the function and what parameters it needs.
    You got /3 concepts.