<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class=""></span><span class="">Why do we keep this behaviour ? : </span><div class=""><div dir="ltr" class=""><div class=""><div class=""><span class="">np.nansum([np.nan]) # zero<br class=""></span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Firstly, you lose information. </span></div><div class=""><span class="">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.</span></div><div class=""><span class="">It is not convenient, useful.</span></div><div class=""><span class="">Secondly, it is illogical. A arithmetic operation or whatever else between Nothing and Nothing cannot return Something.</span></div><div class=""><span class="">We can accept that Nothing + Object = Object but we cannot get a figure from nothing. It is counterintuitive. </span>I really disagree with this change happened few years ago.</div><div class=""><br class=""></div><div class=""><span class=""><br class=""></span></div></div></div><div class=""><div><blockquote type="cite" class=""><div class="">On 24 Oct 2015, at 01:11, Benjamin Root <<a href="mailto:ben.v.root@gmail.com" class="">ben.v.root@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class="">The change to nansum() happened several years ago. The main thrust of it was to make the following consistent:<br class=""><br class=""></div>np.sum([])  # zero<br class=""></div>np.nansum([np.nan])  # zero<br class=""></div>np.sum([1])  # one<br class=""></div>np.nansum([np.nan, 1])  # one<br class=""><br class=""></div><div class="">If you want to propagate masks and such, use masked arrays.<br class=""></div>Ben Root<br class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Oct 23, 2015 at 12:45 PM, Charles Rilhac <span dir="ltr" class=""><<a href="mailto:webmastertux1@gmail.com" target="_blank" class="">webmastertux1@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><p style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255);margin-top:0px!important" class="">Hello,</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255)" class="">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.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255)" class="">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.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255)" class="">Secondly, it's counterintuitive and not convenient. Because, if you want to fill the result of nanfunction you can do that easily :</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255);overflow:visible!important" class=""><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:11.9px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;background-color:rgb(247,247,247)" class="">a <span style="color:rgb(167,29,93)" class="">=</span> np.array([[np.nan, np.nan], [<span style="color:rgb(0,134,179)" class="">1</span>,np.nan]])
a <span style="color:rgb(167,29,93)" class="">=</span> np.nansum(a, <span class="">axis</span><span style="color:rgb(167,29,93)" class="">=</span><span style="color:rgb(0,134,179)" class="">1</span>)
<span style="color:rgb(167,29,93)" class="">print</span>(a)
array([np.nan,  <span style="color:rgb(0,134,179)" class="">1.</span>])
a[np.isnan(a)] <span style="color:rgb(167,29,93)" class="">=</span> <span style="color:rgb(0,134,179)" class="">0</span></pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255)" class="">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.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255)" class="">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.</p><div style="margin-top:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:14px;line-height:22.4px;background-color:rgb(255,255,255);margin-bottom:0px!important" class="">Thank for your work guys ;-)</div></div><br class="">_______________________________________________<br class="">
NumPy-Discussion mailing list<br class="">
<a href="mailto:NumPy-Discussion@scipy.org" class="">NumPy-Discussion@scipy.org</a><br class="">
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank" class="">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">NumPy-Discussion mailing list<br class=""><a href="mailto:NumPy-Discussion@scipy.org" class="">NumPy-Discussion@scipy.org</a><br class="">https://mail.scipy.org/mailman/listinfo/numpy-discussion<br class=""></div></blockquote></div><br class=""></div></div></body></html>