I need to store a numpy array of shape (2000,720,1280) which is created in every loop. My code looks like:
U_list = []
for N_f in range(N):
U = somefunction(N_f)
U_list.append(U)
del U
So I delete the matrix U in every loop because my RAM get full.
Is this a good method to store the matrix U or would you recommend another solution? I compare the code to matlab and matlab need the half time to compute. I think the storage of U in a list could be the reason.
Uarrays are each 2000x720x1280? What'sN? One option may be to preallocate a single large NumPy array and refactorsomefunctionto write directly to a slice of that array, rather than appending in a loop.somefunctionso it just computes the data you're interested in?