[Numpy-discussion] the mean, var, std of empty arrays

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Nov 21 21:45:13 EST 2012


On Wed, Nov 21, 2012 at 9:22 PM, Olivier Delalleau <shish at keba.be> wrote:
> Current behavior looks sensible to me. I personally would prefer no warning
> but I think it makes sense to have one as it can be helpful to detect issues
> faster.

I agree that nan should be the correct answer.
(I gave up trying to define a default for 0/0 in scipy.stats ttests.)

some funnier cases

>>> np.var([1], ddof=1)
0.0
>>> np.var([1], ddof=5)
-0
>>> np.var([1,2], ddof=5)
-0.16666666666666666
>>> np.std([1,2], ddof=5)
nan

But maybe my numpy is too old on my open interpreter
>>> np.__version__
'1.5.1'

Josef

>
> -=- Olivier
>
> 2012/11/21 Charles R Harris <charlesr.harris at gmail.com>
>>
>> What should be the value of the mean, var, and std of empty arrays?
>> Currently
>>
>> In [12]: a
>> Out[12]: array([], dtype=int64)
>>
>> In [13]: a.mean()
>> Out[13]: nan
>>
>> In [14]: a.std()
>> Out[14]: nan
>>
>> In [15]: a.var()
>> Out[15]: nan
>>
>> I think the nan comes from 0/0. All of these also raise warnings the first
>> time they are called.
>>
>> Chuck
>>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list