Why do we keep this behaviour ? : np.nansum([np.nan]) # zero Firstly, you lose information. You can easily fill nan with zero after applying nansum but you cannot keep nan for nan-full rows if you doesn’t have a mask or keep the information about nan-full row before. It is not convenient, useful. Secondly, it is illogical. A arithmetic operation or whatever else between Nothing and Nothing cannot return Something. We can accept that Nothing + Object = Object but we cannot get a figure from nothing. It is counterintuitive. I really disagree with this change happened few years ago.
> On 24 Oct 2015, at 01:11, Benjamin Root <ben.v.r...@gmail.com> wrote: > > 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 > <mailto: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 <mailto:NumPy-Discussion@scipy.org> > https://mail.scipy.org/mailman/listinfo/numpy-discussion > <https://mail.scipy.org/mailman/listinfo/numpy-discussion> > > > _______________________________________________ > 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