Skip to content Skip to sidebar Skip to footer

How Slicing Numpy Load File Is Loaded Into Memory

If I want to load a portion of a file using numpy.load, I use slicing as: np.load('myfile.npy')[start:end]. Does this guarantee that this portion from the file, i.e., [start:end],

Solution 1:

That loads the whole thing. If you don't want to load the whole thing, you could mmap the file and only copy the part you want:

part = numpy.load('myfile.npy', mmap_mode='r')[start:end].copy()

Post a Comment for "How Slicing Numpy Load File Is Loaded Into Memory"