Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'linear': 0.09; 'runtime': 0.09; 'things,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'fancy': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'nan': 0.16; 'nans': 0.16; 'numpy': 0.16; 'propagated': 0.16; 'sorts': 0.16; 'exception': 0.16; 'appropriate': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'written,': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'on,': 0.29; '(this': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; '"",': 0.31; 'bad.': 0.31; 'crash': 0.31; 'division': 0.31; 'file': 0.32; 'url:python': 0.33; 'community': 0.33; 'running': 0.33; '(most': 0.33; 'case,': 0.35; 'computing': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'raising': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'url:org': 0.36; 'so,': 0.37; 'pm,': 0.38; 'recent': 0.39; 'url:mail': 0.40; 'skip:n 10': 0.64; 'computers': 0.72; 'jul': 0.74; 'subject:For': 0.78; 'divide': 0.84; 'mind:': 0.84; 'on?': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=YYu1opqqFlOrpbTqjuhWlWI0UeQKMt0CBf5oBgV9paU=; b=QlwN8BUgGVAgi+wE5hYwKwokj0tfIiALaU6uGgyCxWLUdG8yAfmWqTLwnqzkou6ZmL lgjDz2TKn0BtXc5LtU9+CJKUFBxieOhNh9o1ld8sKszL/cqG46WEasvBEUVqnQDyxElr B8xw+YwTqitp3vDQn2GMr6Wllx6Eg1wEfYGsChMrksm5jx175cE+6qjPb+Pamok9RKRQ E9hklveIa7SzGMQ1fKvXwZwJPdl2artgcCRtRGfNq3KYuQ90xiV0IQJU++vcjtm5V9eM iS0nIS4hKiy0DjJkcZIpxm8a1Z9JDdOIF6Jmqr/lT90JzTKuSky8W4agLbt0GZEzgA6o MbvQ== MIME-Version: 1.0 X-Received: by 10.50.126.7 with SMTP id mu7mr5912423igb.20.1404841748832; Tue, 08 Jul 2014 10:49:08 -0700 (PDT) Sender: skip.montanaro@gmail.com In-Reply-To: <87wqbn92hj.fsf@elektro.pacujo.net> References: <53BC05FB.4050707@jmunch.dk> <87wqbn92hj.fsf@elektro.pacujo.net> Date: Tue, 8 Jul 2014 12:49:08 -0500 X-Google-Sender-Auth: Y_rkMa67D8e8S_qx3HfJYgSkVnA Subject: Re: NaN comparisons - Call For Anecdotes From: Skip Montanaro To: Marko Rauhamaa Content-Type: text/plain; charset=UTF-8 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404841758 news.xs4all.nl 2869 [2001:888:2000:d::a6]:33114 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74191 >>> 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 wrote: > Skip Montanaro : > >> 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 "", line 1, in > 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