[Numpy-discussion] random number genration

2011-03-31 Thread Alex Ter-Sarkissov
thanks Sturl, your second code works well although I had to divide the vector elements through 128 to get just the binaries ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Warren Weckesser
On Tue, Mar 29, 2011 at 11:59 AM, Sturla Molden wrote: > Den 29.03.2011 16:49, skrev Sturla Molden: > > > > This will not work. A boolean array is not compactly stored, but an > > array of bytes. Only the first bit 0 is 1 with probability p, bits 1 to > > 7 bits are 1 with probability 0. We thus

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Sturla Molden
Den 29.03.2011 16:49, skrev Sturla Molden: > > This will not work. A boolean array is not compactly stored, but an > array of bytes. Only the first bit 0 is 1 with probability p, bits 1 to > 7 bits are 1 with probability 0. We thus have to do this 8 times for > each byte, shift left by range(8), an

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Robert Kern
On Tue, Mar 29, 2011 at 09:49, Sturla Molden wrote: > Den 29.03.2011 15:46, skrev Daniel Lepage: >> >> x = (np.random.random(size)<  p) > > This will not work. A boolean array is not compactly stored, but an > array of bytes. Only the first bit 0 is 1 with probability p, bits 1 to > 7 bits are 1 w

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Sturla Molden
Den 29.03.2011 16:49, skrev Sturla Molden: "Only the first bit 0 is 1 with probability p, bits 1 to 7 bits are 1 with probability 0." That should read: "Only bit 0 is 1 with probability p, bits 1 to 7 are 1 with probability 0." Sorry :) Sturla __

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Sturla Molden
Den 29.03.2011 15:46, skrev Daniel Lepage: > > x = (np.random.random(size)< p) This will not work. A boolean array is not compactly stored, but an array of bytes. Only the first bit 0 is 1 with probability p, bits 1 to 7 bits are 1 with probability 0. We thus have to do this 8 times for each b

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Daniel Lepage
On Tue, Mar 29, 2011 at 5:00 AM, Alex Ter-Sarkissov 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-

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Sturla Molden
Den 29.03.2011 14:56, skrev Sturla Molden: > import numpy as np > def randombits(n, p): > b = (np.random.rand(n*8).reshape((n,8))< p).astype(int) > return (b<< range(8)).sum(axis=1).astype(np.uint8) n is the number of bytes. If you prefer to count in bits: def randombits(n, p):

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Sturla Molden
Den 29.03.2011 11:00, skrev Alex Ter-Sarkissov: > 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? Does

Re: [Numpy-discussion] random number genration

2011-03-29 Thread eat
On Tue, Mar 29, 2011 at 1:29 PM, eat wrote: > Hi, > > On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov > 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 word

Re: [Numpy-discussion] random number genration

2011-03-29 Thread eat
Hi, On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov 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 probabilit

[Numpy-discussion] random number genration

2011-03-29 Thread Alex Ter-Sarkissov
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? thanks ___ NumPy-Discu