I want to generate random array of size N which only contains 0 and 1 but I want my array have some ratio between 0 and 1. For example 90% of array be 1 and the remaining 10% be 0(but I want this 90% be random along whole array).
right now I have:
randomLabel = np.random.randint(2, size=numbers)
But I can't control the ratio between 0 and 1.
Without using numpy, you could do as follows:
If you want an exact 1:9 ratio:
If you want independent 10% probabilities:
or
Its difficult to get an exact count but you can get approximate answer by assuming that
random.random
returns a uniform distribution. This is strictly not the case, but is only approximately true. If you have a truly uniform distribution then it is possible. You can try something like the following:Hope this helps ...