mardi 26 septembre 2017

Generating an array of random variables (positive and negative) that sum up to 1

I am trying to create a numpy array with random variables that sum up to 1, but I also want to include negative values.

I am trying:

size =(50,1)
w = np.array(np.random.random(size))

to create the array and populate with numbers (negative and positive), and this works fine.

Now I am trying to make them sum up to 1 with:

w /= np.sum(w)

But this changes my values to be all positive (eliminating the negative values).

What is the proper way to do an array like this?




Aucun commentaire:

Enregistrer un commentaire