[Numpy-discussion] numarray and NaN ?

Chris Barker Chris.Barker at noaa.gov
Tue Sep 23 13:49:23 EDT 2003

Hi all,

There was a lot of discussion a long while back about how Numeric treats
erros in the middle of an array operation. The way it works is if one
operation in an array has a problem (overflow, division by zero, etc),
an exception is returned. You have no idea which element caused the
problem, and teh whole operation grinds to a halt. Personally, I would
MUCH prefer MATLAB's way of handling this: the problematic operation
results in a -Inf, Inf, or NaN result for that element, and the rest of
the array operation can continue. MATLAB also provides utility functions
along the line of isnan, isinf, etc, so you can check for the
problematic areas later.

There was a fair bit of disagreement over whether Numeric should act
similarly, as well as the problem that not all compilers have the
required IEEE support to make this work.

Anyway, how does numarray handle this issue? I'd love to have the MATLAB
behaviour...I'm writing this because I'm about to have to write a bunch
of code to keep making sure I don't pass a 0 into log(), when I'd be
much happier if I could just replace the NaNs with what I want later.


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the NumPy-Discussion mailing list