Python: Numpy standard deviation error

前端 未结 3 564
轻奢々
轻奢々 2020-12-29 23:13

This is a simple test

import numpy as np
data = np.array([-1,0,1])
print data.std()

>> 0.816496580928

I don\'t understand how this r

3条回答
  •  甜味超标
    2020-12-29 23:58

    It is worth reading the help page for the function/method before suggesting it is incorrect. The method does exactly what the doc-string says it should be doing, divides by 3, because By default ddofis zero.:

    In [3]: numpy.std?
    
    String form: 
    File:        /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py
    Definition:  numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False)
    Docstring:
    Compute the standard deviation along the specified axis.
    
    ...
    
    ddof : int, optional
        Means Delta Degrees of Freedom.  The divisor used in calculations
        is ``N - ddof``, where ``N`` represents the number of elements.
        By default `ddof` is zero.
    

提交回复
热议问题