[Numpy-discussion] Ticket #794 and can o' worms.
Sun Jul 20 21:32:35 CDT 2008
On Sun, Jul 20, 2008 at 3:47 PM, Robert Kern <firstname.lastname@example.org> wrote:
> On Sun, Jul 20, 2008 at 17:42, Charles R Harris
> <email@example.com> wrote:
> > Hi All,
> > I "fixed" ticket #754, but it leads to a ton of problems. The original
> > discussion is here. The problems that arise come from conversion to
> > different types.
> > In : a
> > Out: array([ Inf, -Inf, NaN, 0., 3., -3.])
> > In : sign(a).astype(int)
> > Out:
> > array([ 1, -1, -2147483648, 0, 1,
> > -1])
> > In : sign(a).astype(bool)
> > Out: array([ True, True, True, False, True, True], dtype=bool)
> > In : sign(a)
> > Out: array([ 1., -1., NaN, 0., 1., -1.])
> > In : bool(NaN)
> > Out: True
> > So there are problems with at minimum the following.
> > 1) The way NaN is converted to bool. I think it should be False.
> It's not really our choice. That's Python's bool(). For the things
> that are our choice (e.g. array([nan]).astype(bool)) I think we should
> stay consistent with Python.
I agree that this is a good goal. However, in the past, Python's treatment
of NaNs has been rather platform dependent and add hock. In this case, I
suspect that you are OK since the section "Truth Value Testing" in the
Python docs is pretty clear that any non-zero value of a numerical type is
> > 2) The way NaN is converted to int types. I think it should be 0.
> I agree. That's what int(nan) gives:
> >>> int(nan)
This is GvR in
*If long(nan) or int(nan) returns 0 on most platforms in 2.5, we should*
*fix them to always return 0 in 2.5 *and* 2.6. In 3.0 they should raise*
This implies that in version 2.4 and earlier, the Python behaviour is
platform dependent. And that 3.0 this is going to change to raise a
ValueError. Whether it's more important to match current behaviour (return
0) or future behaviour (raise ValueError), I'm not certain. I would lean
towards a ValueError since it's less long term pain and it's IMO more
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion