On Wed, Jun 5, 2013 at 10:09 PM, Robert Bradshaw <
robe...@gmail.com> wrote:
> These are the API functions, which is different than buffer support.
> One additional step compared to any other type would be inserting the
> right hooks on assignment to coerce to 0/1. Probably not hard, simply
> not (as far as I know) implemented.
Fair enough. And you're right, there isn't much difference between a
array of uint8 and a bool array -- on the numpy side, it's mostly
about display (you see [True, False, False]) and a few other niceties.
in may case, a key one was:
In [6]: bool_arr = np.ones((3,), dtype=np.bool)
In [7]: bool_arr
Out[7]: array([ True, True, True], dtype=bool)
In [8]: ~bool_arr
Out[8]: array([False, False, False], dtype=bool)
In [9]: int_arr = np.ones((3,), dtype=np.uint8)
In [10]: int_arr
Out[10]: array([1, 1, 1], dtype=uint8)
In [11]: ~int_arr
Out[11]: array([254, 254, 254], dtype=uint8)
technically, "~" is bitwise, so it all makes sense, but not the result
I wanted! Of course:
In [12]: np.logical_not(int_arr)
Out[12]: array([False, False, False], dtype=bool)
is probably the way to go anyway..
NOTE: I have seen some discussion about "bool" here -- and there a
bool in the C99 standard.. could that simply be used (maybe not
guaranteed to be a one-byte value, though)
Thanks,
-- Chris