Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74188 > unrolled thread
| Started by | Skip Montanaro <skip@pobox.com> |
|---|---|
| First post | 2014-07-08 12:23 -0500 |
| Last post | 2014-07-08 12:49 -0500 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NaN comparisons - Call For Anecdotes Skip Montanaro <skip@pobox.com> - 2014-07-08 12:23 -0500
Re: NaN comparisons - Call For Anecdotes Marko Rauhamaa <marko@pacujo.net> - 2014-07-08 20:36 +0300
Re: NaN comparisons - Call For Anecdotes Skip Montanaro <skip@pobox.com> - 2014-07-08 12:49 -0500
| From | Skip Montanaro <skip@pobox.com> |
|---|---|
| Date | 2014-07-08 12:23 -0500 |
| Subject | Re: NaN comparisons - Call For Anecdotes |
| Message-ID | <mailman.11644.1404840246.18130.python-list@python.org> |
On Tue, Jul 8, 2014 at 9:53 AM, Anders J. Munch <2014@jmunch.dk> wrote: > Most people don't need to deal with NaN's in Python at all, > fortunately. They just don't appear in normal computation, because the > interpreter raises an exception instead. In addition to what others have written, I will add one thing. There are certainly situations where raising an exception is bad. Consider all the people in the scientific computing community doing fancy linear algebra sorts of things, often with missing data. They generally want NaN propagated and not have some long running calculation crash in the middle. Skip
[toc] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-07-08 20:36 +0300 |
| Message-ID | <87wqbn92hj.fsf@elektro.pacujo.net> |
| In reply to | #74188 |
Skip Montanaro <skip@pobox.com>:
> In addition to what others have written, I will add one thing. There
> are certainly situations where raising an exception is bad. Consider
> all the people in the scientific computing community doing fancy
> linear algebra sorts of things, often with missing data. They
> generally want NaN propagated and not have some long running
> calculation crash in the middle.
Do the scientific computers mind:
>>> 1 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
or would they prefer their fancy linear-algebraic computation to just
forge on?
Marko
[toc] | [prev] | [next] | [standalone]
| From | Skip Montanaro <skip@pobox.com> |
|---|---|
| Date | 2014-07-08 12:49 -0500 |
| Message-ID | <mailman.11645.1404841758.18130.python-list@python.org> |
| In reply to | #74190 |
>>> import numpy
>>> a1 = numpy.ones(5)
>>> a1
array([ 1., 1., 1., 1., 1.])
>>> a0 = numpy.zeros(5)
>>> a0
array([ 0., 0., 0., 0., 0.])
>>> a1 / a0
__main__:1: RuntimeWarning: divide by zero encountered in true_divide
array([ inf, inf, inf, inf, inf])
>>> nans = numpy.array([float("nan")] * 5)
>>> nans
array([ nan, nan, nan, nan, nan])
>>> a1 / nans
array([ nan, nan, nan, nan, nan])
>>> a1 / a0 * nans
array([ nan, nan, nan, nan, nan])
You get a runtime warning (this is in Python 2.7), but the division
returns the appropriate value, in this case, infinity. So, yes, they
forge on, and NaN taints things just about the way you'd expect.
Skip
On Tue, Jul 8, 2014 at 12:36 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Skip Montanaro <skip@pobox.com>:
>
>> In addition to what others have written, I will add one thing. There
>> are certainly situations where raising an exception is bad. Consider
>> all the people in the scientific computing community doing fancy
>> linear algebra sorts of things, often with missing data. They
>> generally want NaN propagated and not have some long running
>> calculation crash in the middle.
>
> Do the scientific computers mind:
>
> >>> 1 / 0
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ZeroDivisionError: division by zero
>
> or would they prefer their fancy linear-algebraic computation to just
> forge on?
>
>
> Marko
> --
> https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web