numpy icon indicating copy to clipboard operation
numpy copied to clipboard

mean of an empty list

Open shuaitang opened this issue 7 years ago • 3 comments

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]

shuaitang avatar Apr 19 '19 01:04 shuaitang

There's some good discussion on stack exchange about why NaN is correct behavior here.

eric-wieser avatar Apr 19 '19 01:04 eric-wieser

Thanks!

shuaitang avatar Apr 19 '19 01:04 shuaitang

3q

lucky-lidong avatar Aug 18 '21 07:08 lucky-lidong