I'm working on a bigger projekt and there i see a contiuous increase of memory usage. The code is similar to my demonstration sniped below - just not with random numbers and more usefull calculations... But the effect is the same. Running this i see increasing memory usage
Why is that happening and how can I prevent this? Thank you for every usefull answer :)
I'm using python 3
n= 10000000
indat = np.random.random(n*4)
data = np.zeros(n*3)
d = [0,0,0,0]
for i in range(n):
d = indat[i*4:i*4+4]
data[i*3] = np.sqrt(np.abs(d[0]+d[1]*d[3]))
data[i*3+1]= np.sqrt(np.abs(d[3]+d[2]*d[3]))
data[i*3+2]= np.sqrt(np.abs(d[2]+d[1]*d[3]))
EDIT: I tried some more stuff:
1: This works as expected - no memory increase
for i in range(n):
print(i, end="\r")
2: But with this there is that increase.
for i in range(n):
data[i] = indat[i]**2
So at minimum this simple copy is not working as i expect it to... How do I get python to store the result of my calculation in the already allocated memory?