![](https://secure.gravatar.com/avatar/71832763447894e7c7f3f64bfd19c13f.jpg?s=120&d=mm&r=g)
On 09/29/2015 11:39 AM, josef.pktd@gmail.com wrote:
On Tue, Sep 29, 2015 at 11:25 AM, Anne Archibald <archibald@astron.nl <mailto:archibald@astron.nl>> wrote:
IEEE 754 has signum(NaN)->NaN. So does np.sign on floating-point arrays. Why should it be different for object arrays?
Anne
P.S. If you want exceptions when NaNs appear, that's what np.seterr is for. -A
I also think NaN should be treated the same way as floating point numbers (whatever that is). Otherwise it is difficult to remember when nan is essentially a float dtype or another dtype. (given that float is the smallest dtype that can hold a nan)
Note that I've reimplemented np.sign for object arrays along these lines in this open PR: https://github.com/numpy/numpy/pull/6320 That PR recursively uses the np.sign ufunc to evaluate object arrays containing float and complex numbers. This way the behavior on object arrays is identical to float/complex arrays. Here is what the np.sign ufunc does (for arbitrary x): np.sign(np.nan) -> nan np.sign(complex(np.nan, x)) -> complex(nan, 0) np.sign(complex(x, np.nan)) -> complex(nan, 0) Allan