What is the efficient(probably vectorized with Matlab terminology) way to generate random number of zeros and ones with a specific proportion? Specially with Numpy?
You can use numpy.random.binomial. E.g. suppose frac is the proportion of ones:
numpy.random.binomial
frac
In [50]: frac = 0.15 In [51]: sample = np.random.binomial(1, frac, size=10000) In [52]: sample.sum() Out[52]: 1567