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
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
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
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
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
__
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
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-
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):
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
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
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
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
12 matches
Mail list logo