[Numpy-discussion] proposal of new keywords for np.nan_to_num

kikocorreoso kachine at protonmail.com
Thu Apr 4 13:11:03 EDT 2019


Hi all,

I propose to add some keywords to nan_to_num function. The addition do not modify the actual behavior. Information related with this addition can be found in these links:
https://github.com/numpy/numpy/pull/13219
https://github.com/numpy/numpy/pull/9355

The basic idea is to allow the user to use their own defined values when replacing nan, positive infinity and/or negative infinity. The proposed names for the keywords are 'nan', posinf', and 'neginf' respectively. So the usage would be something like this:

>>> a = np.array((np.nan, 2, 3, np.inf, 4, 5, -np.inf))
>>> np.nan_to_num(a, nan=-999)
array([-9.99000000e+002,  2.00000000e+000,  3.00000000e+000,
        1.79769313e+308,  4.00000000e+000,  5.00000000e+000,
       -1.79769313e+308])
>>> np.nan_to_num(a, posinf=np.nan, neginf=np.nan)
array([ 0.,  2.,  3., nan,  4.,  5., nan])

Please, could you comment if it would be useful the addition?, if the PR needs any change?...

Thanks to Eric, Joseph, Allan and Matti for their comments and revisions on GH.

Kind regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190404/34f6b484/attachment.html>


More information about the NumPy-Discussion mailing list