jeudi 8 juin 2017

How to make an array with random numbers, with one condition repeated n number of times?

I have an array which I fill with random floating numbers from 0 to 1.

x = np.random.random((20,20))

Later on, I will extract the items in the array (x[row][column]) which are larger than 0.2,with this:

loc = np.argwhere(x > 0.2)

However,I cannot control the size of the loc. I have to have maximum 80 elements which are providing the condition of being larger than 0.2.

maxnum = 80
len(loc) == maxnum

And the [row][column] combinations of the items which provide being larger than 0.2 should be different each time, as it should be a random array.

Do you know how to achieve that output?




Aucun commentaire:

Enregistrer un commentaire