numpy
numpy copied to clipboard
mean of an empty list
The mean of an empty list is 'nan', which is supposed to be 0 I believe.
Reproducing code example:
import numpy as np
np.mean([])
Error message:
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice. out=out, **kwargs) /usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:85: RuntimeWarning: invalid value encountered in double_scalars ret = ret.dtype.type(ret / rcount)
Numpy/Python version information:
1.16.0 3.6.7 (default, Oct 25 2018, 09:16:13) [GCC 5.4.0 20160609]
There's some good discussion on stack exchange about why NaN is correct behavior here.
Thanks!
3q