np.stdでRuntimeWarning: Degrees of freedom <= 0 for sliceと出た

Jan. 28, 2020, 6:34 a.m.

#NumPy  #Python 

>>> np.std([1],ddof=0)
0.0
>>> np.std([1],ddof=1)
/usr/local/lib/python3.7/site-packages/numpy/core/_methods.py:217: RuntimeWarning: Degrees of freedom <= 0 for slice
  keepdims=keepdims)
/usr/local/lib/python3.7/site-packages/numpy/core/_methods.py:209: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
nan

後者はddof=1で\(n-1\)にしてるんだからそれはそうという話。