I have a big numpy array my_array that I copy into another temporary array temp_my_array in order to use it in calculations inside a loop, as following:
my_array = [10.1, 20.3, ..., 11.2] # a large numpy array
temp_my_array = np.copy(my_array)
for i in range(200000):
for item in np.where(my_array> 5):
temp_my_array[item] = f(my_array[some other items])
my_array = np.copy(temp_my_array)
I have memory error with np.copy when my_array is so big. Besides, profiling showed that np.copy is the slowest part of my code. Any ideas please?
temp_my_arrayit doesn't change the same item inmy_array.my_arrayin your function call.my_array[item] = f(my_array[item])and not bother with your temp array? The iterator you've created withnp.wherewill not reference the changingmy_arrayinside the loop.