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 are 1 with probability 0. We thus have to do this 8 times for > each byte, shift left by range(8), and combine them with binary or.
It's not clear that the OP really meant bits rather than just bools. Judging by the example that he tried first, it's likely that he just wants bools (or even just 0s and 1s) and not a real string of bits compacted into bytes. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion