I need to handle some large numpy
arrays in my project. After such an array is loaded from the disk, over half of my computer's memory will be consumed.
After the array is loaded, I make several slices (almost half of the array will be selected) of it, then I receive error tells me the memory is insufficient.
By doing a little experiment I understand, I receive the error because when a numpy
array is sliced, a copy will be created
import numpy as np
tmp = np.linspace(1, 100, 100)
inds = list(range(100))
tmp_slice = tmp[inds]
assert id(tmp) == id(tmp_slice)
returns AssertionError
Is there a way that a slice of a numpy
array only refers to the memory addresses of the original array thus data entries are not copied?