[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

[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 p1/2 and 0 with probability q=1-p? thanks ___

Re: [Numpy-discussion] random number genration

2011-03-29 Thread eat
Hi, On Tue, Mar 29, 2011 at 12:00 PM, Alex Ter-Sarkissov ater1...@gmail.comwrote: 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 p1/2 and 0

Re: [Numpy-discussion] random number genration

2011-03-29 Thread eat
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.comwrote: 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

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 p1/2 and 0 with probability q=1-p? Does this

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 Daniel Lepage
On Tue, Mar 29, 2011 at 5:00 AM, 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 p1/2 and 0 with

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

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 Robert Kern
On Tue, Mar 29, 2011 at 09:49, Sturla Molden stu...@molden.no 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

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), and

Re: [Numpy-discussion] random number genration

2011-03-29 Thread Warren Weckesser
On Tue, Mar 29, 2011 at 11:59 AM, Sturla Molden stu...@molden.no 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.