[Numpy-discussion] ufunc oddities

Charles R Harris charlesr.harris@gmail....
Sat May 24 21:45:09 CDT 2008


On Sat, May 24, 2008 at 8:40 PM, Robert Kern <robert.kern@gmail.com> wrote:

> On Sat, May 24, 2008 at 9:37 PM, Charles R Harris
> <charlesr.harris@gmail.com> wrote:
> >
> >
> > On Sat, May 24, 2008 at 8:25 PM, Robert Kern <robert.kern@gmail.com>
> wrote:
> >>
> >> On Sat, May 24, 2008 at 9:09 PM, Charles R Harris
> >> <charlesr.harris@gmail.com> wrote:
> >> >
> >> > On Sat, May 24, 2008 at 7:47 PM, Robert Kern <robert.kern@gmail.com>
> >> > wrote:
> >> >>
> >> >> On Sat, May 24, 2008 at 8:31 PM, Charles R Harris
> >> >> <charlesr.harris@gmail.com> wrote:
> >> >> > Hi All,
> >> >> >
> >> >> > I'm writing tests for ufuncs and turned up some oddities:
> >> >> >
> >> >> > In [4]: degrees(True)
> >> >> > Out[4]: 57.29578
> >> >> >
> >> >> > In [5]: radians(True)
> >> >> > Out[5]: 0.017453292
> >> >> >
> >> >> > In [6]: sin(True)
> >> >> > Out[6]: 0.84147096
> >> >> >
> >> >> > Do we want numeric functions to apply to booleans?
> >> >>
> >> >> I don't see a good reason to prevent it. They are just 0 and 1 under
> >> >> the covers and behave like it everywhere else (e.g. True + True == 2
> >> >> and the very useful boolean_mask.sum()).
> >> >
> >> > True + True == 1
> >>
> >> No, True + True == 2. Try it. We might have made boolean arrays behave
> >> differently than Python bool objects, but that's not what I wrote.
> >
> > Robert, the C code in the inner loop is generated with
> >
> > /**begin repeat
> >
> >    #TYPE=(BOOL,
> >
> BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#
> >    #OP=||, +*13, ^, -*13#
> >    #kind=add*14, subtract*14#
> >    #typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong,
> longlong,
> > ulonglong, float, double, longdouble)*2#
> > */
> >
> > Note that || is not the same as +. Also note that subtract is implemented
> as
> > xor.
>
> I'm not sure why you're showing me numpy C code. I am talking about
> the Python bools True and False.


Because I'm talking about ufuncs. The original question was about ufuncs
and, since array booleans are not treated as numbers for ordinary
arithmetic, the question was when *do* we treat them as numbers. I'm a
bugger for consistency and booleans aren't consistent.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080524/b99f6d20/attachment-0001.html 


More information about the Numpy-discussion mailing list