[Numpy-discussion] Best dtype for Boolean values

Robert Kern robert.kern@gmail....
Mon Apr 12 11:53:10 CDT 2010


On Mon, Apr 12, 2010 at 10:59, John Jack <itsmilesdavis@gmail.com> wrote:
> Hello all.
> I am (relatively) new to python, and 100% new to numpy.
> I need a way to store arrays of booleans and compare the arrays for
> equality.
> I assume I want arrays of dtype Boolean, and I should compare the arrays
> with array_equal
>>>> tmp.all_states
> array([False,  True, False], dtype=bool)
>>>> tmp1.all_states
> array([False, False, False], dtype=bool)
>>>> tmp1.all_states[1]=True
>>>> tmp1.all_states
> array([False,  True, False], dtype=bool)
>>>> array_equal(tmp.all_states,tmp1.all_states)
> True
>>>> any(tmp.all_states)
> True
> Would this be (a) the cheapest way (w.r.t. memory) to store Booleans and

Yes.

> (b)
> the most efficient way to compare two lists of Booleans?

Yes.

-- 
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


More information about the NumPy-Discussion mailing list