[Numpy-discussion] SWIGed function does not like my boolean array

Sebastian Haase haase@msg.ucsf....
Wed Nov 7 11:35:41 CST 2007


On Nov 7, 2007 5:23 PM, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
>
> > I don't understand.  I'm thinking of most math functions in the
> > C-library. In C a boolean is just an integer of 0 or 1 (quasi, by
> > definition).
> >
> > Could you explain what you mean ?
> >
>
> In C++, bool is a new type that has two values, true and false. If you add
> true and true, it is still true, and not 2. In C, everything that is not 0
> is true, not in C++.

Yes, I know this. But my situation is "the other way around". Lets say
I want to count "foreground pixels" in an image: I would want to "sum"
all the true values, i.e. a true *is* a 1 and a false *is* a 0.

In other words, I'm really thinking of (older kind of) C, where there
*was* no bool.
I assume this thinking still applies to the internal arithmetic of CPUs today.
Also the "bit-values" of a boolean array (in memory) are set this way
already anyway !

How can I simply call my functions looking at these bit values ?
(essentially interpreting a boolean true as 1 and false as 0)

-Sebastian


More information about the Numpy-discussion mailing list