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

Skipper Seabold jsseabold@gmail....
Wed Nov 21 20:38:13 CST 2012


On Wed, Nov 21, 2012 at 9:22 PM, Olivier Delalleau <shish@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.
>
> -=- Olivier
>

It's configurable.

[~/]
[1]: np.seterr(all='ignore')

[1]: {'divide': 'ignore', 'invalid': 'ignore', 'over': 'ignore', 'under':
'ignore'}

[~/]
[2]: np.array([]).mean()

[2]: nan

[~/]
[3]: np.seterr(all='warn')

[3]: {'divide': 'ignore', 'invalid': 'ignore', 'over': 'ignore', 'under':
'ignore'}

[~/]
[4]: np.array([]).mean()

/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.py:57:
RuntimeWarning: invalid value encountered in double_scalars
  ret = ret / float(rcount)
[4]: nan

Skipper


> 2012/11/21 Charles R Harris <charlesr.harris@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@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121121/cb318fac/attachment.html 


More information about the NumPy-Discussion mailing list