<div dir="ltr"><div>This is going to need to be heavily documented with doctests. Also, just to clarify, are we talking about a ValueError for doing a nansum on an empty array as well, or will that now return a zero?<br><br>

</div>Ben Root<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 15, 2013 at 9:52 AM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><br><div class="gmail_quote"><div><div class="h5">On Sun, Jul 14, 2013 at 3:35 PM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div>On Sun, Jul 14, 2013 at 2:55 PM, Warren Weckesser <span dir="ltr"><<a href="mailto:warren.weckesser@gmail.com" target="_blank">warren.weckesser@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 7/14/13, Charles R Harris <<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>> wrote:<br>
> Some corner cases in the mean, var, std.<br>
><br>
</div>> *Empty arrays*<br>
<div>><br>
> I think these cases should either raise an error or just return nan.<br>
> Warnings seem ineffective to me as they are only issued once by default.<br>
><br>
> In [3]: ones(0).mean()<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:61:<br>
> RuntimeWarning: invalid value encountered in double_scalars<br>
>   ret = ret / float(rcount)<br>
> Out[3]: nan<br>
><br>
> In [4]: ones(0).var()<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:76:<br>
> RuntimeWarning: invalid value encountered in true_divide<br>
>   out=arrmean, casting='unsafe', subok=False)<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:100:<br>
> RuntimeWarning: invalid value encountered in double_scalars<br>
>   ret = ret / float(rcount)<br>
> Out[4]: nan<br>
><br>
> In [5]: ones(0).std()<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:76:<br>
> RuntimeWarning: invalid value encountered in true_divide<br>
>   out=arrmean, casting='unsafe', subok=False)<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:100:<br>
> RuntimeWarning: invalid value encountered in double_scalars<br>
>   ret = ret / float(rcount)<br>
> Out[5]: nan<br>
><br>
</div>> *ddof >= number of elements*<br>
<div>><br>
> I think these should just raise errors. The results for ddof >= #elements<br>
> is happenstance, and certainly negative numbers should never be returned.<br>
><br>
> In [6]: ones(2).var(ddof=2)<br>
> /home/charris/.local/lib/python2.7/site-packages/numpy/core/_methods.py:100:<br>
> RuntimeWarning: invalid value encountered in double_scalars<br>
>   ret = ret / float(rcount)<br>
> Out[6]: nan<br>
><br>
> In [7]: ones(2).var(ddof=3)<br>
> Out[7]: -0.0<br>
</div>> *<br>
> nansum*<br>
<div>><br>
> Currently returns nan for empty arrays. I suspect it should return nan for<br>
> slices that are all nan, but 0 for empty slices. That would make it<br>
> consistent with sum in the empty case.<br>
><br>
<br>
<br>
</div>For nansum, I would expect 0 even in the case of all nans.  The point<br>
of these functions is to simply ignore nans, correct?  So I would aim<br>
for this behaviour:  nanfunc(x) behaves the same as func(x[~isnan(x)])<br>
<br></blockquote></div></div><div><br>Agreed, although that changes current behavior. What about the other cases? <br><br></div></div></blockquote></div></div><div><br>Looks like there isn't much interest in the topic, so I'll just go ahead with the following choices:<br>


<br>Non-NaN case<br><br>1) Empty array -> ValueError<br><br>The current behavior with stats is an accident, i.e., the nan arises from 0/0. I like to think that in this case the result is any number, rather than not a number, so *the* value is simply not defined. So in this case raise a ValueError for empty array.<br>


<br>2) ddof >= n -> ValueError<br><br>If the number of elements, n, is not zero and ddof >= n, raise a ValueError for the ddof value.<br><br>Nan case<br><br>1) Empty array -> Value Error<br>2) Empty slice -> NaN<br>


3) For slice ddof >= n -> Nan<br><br> Chuck<br></div><br></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>