[Numpy-discussion] ma.std(ddof=1) bug?

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Apr 23 13:45:10 EDT 2010


Is there a reason why ma.std(ddof=1)  does not calculated the std if
there are 2 valid values?

example
nan = np.nan
x1 = np.array([[9.0, 3.0, nan, nan, 9.0, nan],
              [1.0, 1.0, 1.0, nan, nan, nan],
              [2.0, 2.0, 0.01, nan, 1.0, nan],
              [3.0, 9.0, 2.0, nan, nan, nan],
              [4.0, 4.0, 3.0, 9.0, 2.0, nan],
              [5.0, 5.0, 4.0, 4.0, nan, nan]])

>>> print np.ma.fix_invalid(x1).std(0, ddof=0)
[2.58198889747 2.58198889747 1.41138796934 2.5 3.55902608401 --]

>>> print np.ma.fix_invalid(x1).std(0, ddof=1)
[2.82842712475 2.82842712475 1.57797972104 -- 4.35889894354 --]     #
invalid column 3

scipy stats  (bias=True is default)
>>> print stats.nanstd(x1,0)
[ 2.82842712  2.82842712  1.57797972  3.53553391  4.35889894         NaN]

numpy with valid values
>>> np.array((9,4.)).std(ddof=1)
3.5355339059327378

Josef



More information about the NumPy-Discussion mailing list