2 years ago
#34340
Fubudis
Calculating variance on a large number of samples in Python
I'm running a Monte Carlo simulation in python and storing the results of each trial in a list outcomes[]
. Right now I'm running the sim for 5M trials.
I'm trying to use Numpy to calculate the variance of the list with:
print("Var: " + str(np.var(outcomes)))
For some reason when I try to calculate the variance of outcomes[] the simulation takes an extremely long time to finish. Normally it'll take 10-30 minutes to run for 5M trials but with the single np.var(outcomes)
line I've yet to see it complete (even after 2 hours).
Is there a more efficient way to calculate variance by either using a different function or storing the data in something other than a list?
python
list
numpy
statistics
variance
0 Answers
Your Answer