How do you handle memory-mapped files in NumPy for large datasets, and what are the benefits?

Quick Overview

Asks how to work with NumPy arrays larger than RAM using memory-mapped files through np.memmap or np.load with mmap_mode. Tests understanding of access modes, flushing writes, chunked processing, and how memory order and OS page caching affect performance.

How do you handle memory-mapped files in NumPy for large datasets, and what are the benefits?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you handle memory-mapped files in NumPy for large datasets, and what are the benefits? Assume the array you need to work with is larger than the RAM of the machine you are on. ```hint Where the bytes live Think about what the operating system does when your code touches an element of an array whose data sits in a file on disk. ``` ```hint Access pattern Consider how the array's memory order and the slices you take decide how many disk pages get read. ``` ### What a Strong Answer Covers - What memory mapping does at the operating system level and why it lets an array exceed RAM. - The NumPy entry points for `.npy` files and for raw binary files, the access modes, and how writes reach the file. - How to process the mapped array in chunks so that intermediate results stay small. - The benefits, each with a reason. - The performance caveats and the operations that quietly allocate a full in-memory array. ### Follow-up Questions - How would you standardize every column of a memory-mapped matrix without loading it into RAM? - How does a memory-mapped array behave when several worker processes read or write it? - Why is reading a single column of a large C-ordered memmap slow, and how would you change the storage to fix it? - When would you choose HDF5, Zarr or Parquet over a raw memory-mapped file?

Overview: Asks how to work with NumPy arrays larger than RAM using memory-mapped files through np.memmap or np.load with mmap_mode. Tests understanding of access modes, flushing writes, chunked processing, and how memory order and OS page caching affect performance.

PracHub logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you handle memory-mapped files in NumPy for large datasets, and what are the benefits?

Assume the array you need to work with is larger than the RAM of the machine you are on.

What a Strong Answer Covers Guidance

  • What memory mapping does at the operating system level and why it lets an array exceed RAM.
  • The NumPy entry points for .npy files and for raw binary files, the access modes, and how writes reach the file.
  • How to process the mapped array in chunks so that intermediate results stay small.
  • The benefits, each with a reason.
  • The performance caveats and the operations that quietly allocate a full in-memory array.

Follow-up Questions Guidance

  • How would you standardize every column of a memory-mapped matrix without loading it into RAM?
  • How does a memory-mapped array behave when several worker processes read or write it?
  • Why is reading a single column of a large C-ordered memmap slow, and how would you change the storage to fix it?
  • When would you choose HDF5, Zarr or Parquet over a raw memory-mapped file?