0
0
NumPydata~5 mins

Memory-mapped files with np.memmap in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a memory-mapped file in the context of numpy's np.memmap?
A memory-mapped file is a way to access small parts of large files on disk as if they were in memory, without loading the entire file. np.memmap lets numpy treat disk files like arrays, saving memory and speeding up access.
Click to reveal answer
beginner
How does np.memmap help when working with large datasets?
np.memmap allows you to work with large datasets by loading only parts of the data into memory on demand, instead of loading the whole dataset at once. This reduces memory use and can improve performance.
Click to reveal answer
intermediate
What are the key parameters when creating a np.memmap object?
Key parameters include: filename (path to the file), dtype (data type of the array), mode ('r', 'r+', 'w+', etc. for read/write), offset (where to start reading), and shape (array dimensions).
Click to reveal answer
beginner
True or False: Changes made to a np.memmap array are immediately saved to the disk file.
True. When you modify a np.memmap array, the changes are written directly to the disk file, making it useful for large data that doesn't fit in memory.
Click to reveal answer
intermediate
Why might you choose np.memmap over loading a numpy array with np.load?
np.memmap is better for very large files because it doesn't load the entire file into memory. np.load loads the whole array into RAM, which can cause memory errors with big data.
Click to reveal answer
What does np.memmap primarily help with?
ACreating plots from numpy arrays
BCompressing numpy arrays
CSorting numpy arrays faster
DAccessing large files without loading all data into memory
Which mode in np.memmap allows read and write access to the file?
Ar+
Bw+
Cc
Dr
If you want to start reading a np.memmap file from byte 1000, which parameter do you use?
Ashape
Boffset
Cdtype
Dmode
True or False: np.memmap loads the entire file into RAM immediately.
AFalse
BDepends on dtype
COnly for small files
DTrue
What happens when you modify data in a np.memmap array?
AChanges are saved only in memory
BChanges are lost after program ends
CChanges are saved to disk immediately
Dnp.memmap arrays are read-only
Explain how np.memmap helps manage large datasets that don't fit into memory.
Think about how you can open a huge book and read only one page at a time.
You got /4 concepts.
    Describe the main parameters needed to create a np.memmap object and their roles.
    Consider what you need to tell numpy about the file and how you want to use it.
    You got /5 concepts.