Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating the Cumulative Mean in Python

Tags:

python-3.x

i am new on programming and python. I made a simulation mm1 queue. I ran it properly. I took the results. I have an 5000 output. But now i should calculate the cumulative mean of average delays for every 100 period(1 to 100, 1 to 200... until 1 to 5000).

#data 4 (delay time) set assign to list of numpy array
npdelaytime = np.array(data[4][0:5000])  
#reshape the list of delay time 100 customer in each sample
npdelayreshape100 = np.reshape(npdelaytime, (-1,100))     
#mean of this reshape matrix
meandelayreshape100 = np.mean(npdelayreshape100, axis=1)  
cumsummdr100 = np.cumsum(meandelayreshape100)
a = range(1,51)     
meancsmdr100 = cumsummdr100 / a

I can figure this out like this. First reshape the 5000 sample point into to 100*50. Then taking the means of these matrix. Lastly cumsum of these means.

My Question : Is there a easy way to do this ?

like image 423
Harun Horasanlı Avatar asked Oct 26 '18 09:10

Harun Horasanlı


1 Answers

What about replacing range by np.arange ?

Try:

meancsmdr100 = cumsummdr100 / np.arange(1,51)
like image 110
Learning is a mess Avatar answered Oct 31 '22 14:10

Learning is a mess