dimanche 12 juillet 2015

Easiest way to generate random array from {1,-1} with predefined mean value in Numpy?

What is the best way in numpy to generate a random array with n values of the form

    arr = [1,-1,-1,1,1,1,...]

that average out as close as possible to a predefined value m, so that

    print 1/n*np.sum(arr)
    >>> #value that is as close as possible to m

I have been experimenting with

    numpy.random.choice([-1,1], size=n) 

but can't seem to find a solution.




Aucun commentaire:

Enregistrer un commentaire