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?
If I understand your problem correctly, you might get some help with numpy.random.shuffle
>>> def rand_bin_array(K, N): arr = np.zeros(N) arr[:K] = 1 np.random.shuffle(arr) return arr >>> rand_bin_array(5,15) array([ 0., 1., 0., 1., 1., 1., 0., 0., 0., 1., 0., 0., 0., 0., 0.])