vendredi 19 février 2021

How to sample M times from N different normal distributions in python? Is there a "faster" way in terms of processing time?

I need to sample multiple (M) times from N different normal distributions. This repeated sampling will happen in turn several thousand times. I want to do this in the most efficient way, because I would like to not die of old age before this process ends. The code would look something like this:

import numpy as np

# bunch of stuff that is unrelated to the problem

number_of_repeated_processes = 5000
number_of_samples_per_process = 20

# the normal distributions I'm sampling from are described by 2 vectors:
#
# myMEANS <- an numpy array of length 10 containing the means for the distributions
# myVAR <- an numpy array of length 10 containing the variance for the distributions


for i in range(number_of_repeated_processes):
  # myRESULT is a list of arrays containing the results for the sampling
  #
  myRESULT = [np.random.normal(loc=myMEANS[j], scale=myVAR[j], size = number_of_samples_per_process) for j in range(10)]
  #
  # here do something with myRESULT

# end for loop

The questions is... is there a better way to obtain the myRESULT matrix




Aucun commentaire:

Enregistrer un commentaire