I have a numpy.array called combinations (2D array of 336^3=37,933,056 by 3 np.float32), and also an err_np (1D array of 336^3=37,933,056 np.float16), storing the %error of each 3 value combination.
I need to sort combinations by their absolute error, so i do:
from sys import getsizeof as size
import numpy as np
# Some stuff gets done here
print(size(combinations)) # 120 - **EITHER THIS IS TOO LOW**
print(len(combinations)) # 37,933,056
print(combinations) # array OK
combinations = combinations[abs(err_np).argsort()]
print(size(combinations)) # 455,196,792 - **OR THIS IS TOO HIGH**
print(len(combinations)) # 37,933,056
print(combinations) # array sorted OK
I assumed the size before sorting was wrong, but i remind you size() is sys.getsizeof(), and the whole array is in there...
Is there a way to sort an np.array using less memory? It should also be as time-efficient as possible, since the size of the array. I currently del err_np after sorting combinations so i don't care about it.