The change to nansum() happened several years ago. The main thrust of it was to make the following consistent:
np.sum([]) # zero np.nansum([np.nan]) # zero np.sum([1]) # one np.nansum([np.nan, 1]) # one If you want to propagate masks and such, use masked arrays. Ben Root On Fri, Oct 23, 2015 at 12:45 PM, Charles Rilhac <webmastert...@gmail.com> wrote: > Hello, > > I noticed the change regarding nan function and especially nansum > function. I think this choice is a big mistake. I know that Matlab and R > have made this choice but it is illogical and counterintuitive. > > First argument is about logic. An arithmetic operation between Nothing and > Nothing cannot make a figure or an object. Nothing + Object can be an > object or something else, but from nothing, it cannot ensue something else > than nothing. I hope you see what I mean. > > Secondly, it's counterintuitive and not convenient. Because, if you want > to fill the result of nanfunction you can do that easily : > > a = np.array([[np.nan, np.nan], [1,np.nan]]) > a = np.nansum(a, axis=1)print(a) > array([np.nan, 1.]) > a[np.isnan(a)] = 0 > > Whereas, if the result is already filled with zero on NaN-full rows, you > cannot replace the result of NaN-full rows by NaN easily. In the case > above, you cannot because you lost information about NaN-full rows. > > I know it is tough to come back to a previous stage but I really think > that it is wrong to absolutely fill with zeros the result of arithmetic > operation containing NaN. > Thank for your work guys ;-) > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > https://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion