Let's say, that we have a numpy
array storing large objects. My goal is to delete one of these objects from memory, but retain the initial structure of the array. The cell, under which this object was stored might be filled for example with None
.
Example simplified behaviour, where I replaced large objects with characters:
arr = numpy.asarray(['a', 'b', 'c']) # arr = ['a', 'b', 'c']
delete_in_place(arr, 0) # arr = [None, 'b', 'c']
I can't do this by calling numpy.delete()
, because it will just return a new array without one element, which will take additional space in memory. This will also change the shape (by getting rid of given index), which I want to avoid.
My other idea was to just set arr[0] = None
and call the garbage collector, but I'm not sure what the exact behaviour of such procedure would be.
Do you have any ideas on how to do it?