lundi 25 septembre 2017

numpy.random.normal() generates the same set of values when called repeatedly in a loop

My goal is to generate a different set of values using numpy.random.normal(). I have the above inside a function() which is called repeatedly inside a loop. The setup looks something similar to the following when stripped down:

import numpy as np

def errorFn():
    val =  np.random.normal(0, 5., 10)
    print val

for i in range(5):
    errorFn()

And when I run this particular bare-bones version of my program it works as expected and gives me a different set of values every time.

However my actual program is much more complex, and use a ton of additional parameters, functions and the like. But when I put the same exact np.random.normal(0, 5., 10) inside of a function in my code (note that the values I pass to normal() does not depend on any other parameters and are constants.), it generates the exact same set of values every time. Following is how it looks like:

def myFunction(#multiple parameters here):
    # Additional stuff
    print np.random.normal(0, 5., 10)

# call the function like so:

for t in range(5):
    # lots of other stuff
    # myFunction()

What could be the problem? I have defined the functions in a separate script and import them in my program. Could that be the reason? Any help is greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire