On Tue, Mar 29, 2011 at 1:29 PM, eat <e.antero.ta...@gmail.com> wrote:
> Hi, > > On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov > <ater1...@gmail.com>wrote: > >> If I want to generate a string of random bits with equal probability I run >> >> >> random.randint(0,2,size). >> >> What if I want a specific proportion of bits? In other words, each bit is >> 1 with probability p<1/2 and 0 with probability q=1-p? >> > Would it be sufficient to: > In []: bs= ones(1e6, dtype= int) > In []: bs[randint(0, 1e6, 1e5)]= 0 > In []: bs.sum()/ 1e6 > Out[]: 0.904706 > Or: In []: bs= ones(1e6, dtype= int) In []: bs[rand(1e6)< 1./ 10]= 0 In []: bs.sum()/ 1e6 Out[]: 0.89983 > > Regards, > eat > >> >> thanks >> >> _______________________________________________ >> NumPy-Discussion mailing list >> NumPy-Discussion@scipy.org >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion