[Numpy-discussion] nan_to_num and bool arrays

Bruce Southey bsouthey@gmail....
Fri Dec 11 14:08:11 CST 2009


On 12/11/2009 01:33 PM, Robert Kern wrote:
> On Fri, Dec 11, 2009 at 13:11, Bruce Southey<bsouthey@gmail.com>  wrote:
>
>    
>> As documented, nan_to_num returns a float so it does not return the
>> input unchanged.
>>      
Sorry for my mistake:
Given an int input, np.nan_to_num returns an int dtype
 >>> np.nan_to_num(np.zeros((3,3), dtype=np.int)).dtype
dtype('int64')

> I think that is describing the current behavior rather than
> documenting the intent of the function. Given the high level purpose
> of the function, to "[r]eplace nan with zero and inf with finite
> numbers," I think it is fairly reasonable to implement it as a no-op
> for integers and related dtypes. There are no nans or infs for those
> dtypes so the input can be passed back unchanged.
>    

So I agree that it should leave the input untouched when a non-float 
dtype is used for some array-like input.

Bruce




More information about the NumPy-Discussion mailing list