[SciPy-user] Re: nan puzzle
Jim Vickroy
Jim.Vickroy at noaa.gov
Thu Jul 14 09:11:32 CDT 2005
Robert Kern wrote:
> Grant Edwards wrote:
>
>> On 2005-07-13, Alan G Isaac <aisaac at american.edu> wrote:
>
>
>>> Anyway, now I cannot replicate the problem.
>>
>>
>> I still don't understand what the problem is (or was).
>
>
> His original code had
>
> >>> z = [0, 1, nan]
> >>> x = z[2]
> >>> x is nan
> False
>
> Since "is" evaluates based on pointer comparisons and putting
> something in a list or extracting it again by indexing ought to
> preserve those pointers, that result shouldn't happen for any object,
> nan or otherwise.
>
> Of course, "x is nan" is a pretty useless operation as you point out,
> and one really should be using some kind of isnan() function.
> Preferably implemented by someone other than one's self. :-)
>
Sorry, I joined this discussion in mid-stream so I have may have missed
something important, but:
>>> x = [1.0, 2.0, 3.0]
>>> x[2] is 3.0
False
>>> x[2] == 3.0 # even this is risky
True
>>> x.append(None) # None is special
>>> x[3] is None
True
>>> x[3] == None
True
So without knowing the implementation of nan (e.g., is it truly unique
package-wide), I would not expect x is nan to evalutate to True.
Just my 2-cents worth.
-- jv
More information about the SciPy-user
mailing list