Free memory in place

Is there a way to get numpy to free the memory used by the array? I can't just start del arraybecause the array is referenced elsewhere.

An example of why this matters and why I think it is safe:

def run():
   arr = np.array(....)
   arr2 = process(arr)
   fit(arr2)

I can edit process, but not run. arrStores a lot of memory right now , which is no longer needed after startup process. I would like to remove the contents from arrfrom processafter creation arr2.

+4
source share
1 answer

You can try resizing the array to a small array:

arr.resize((2,), refcheck=False)

It modifies the array in place:

a.resize(new_shape, refcheck = True)

.

...

.

( , ) .

- , Python, . , , , Python, refcheck False.

+1

All Articles