If you need an exact ratio of 1: 9:
nums = numpy.ones(1000) nums[:100] = 0 numpy.random.shuffle(nums)
If you need an independent 10% probability:
nums = numpy.random.choice([0, 1], size=1000, p=[.1, .9])
or
nums = (numpy.random.rand(1000) > 0.1).astype(int)
source share