[Numpy-svn] r4967 - in trunk/numpy: core/tests ma/tests

numpy-svn@scip... numpy-svn@scip...
Sat Apr 5 19:40:41 CDT 2008


Author: stefan
Date: 2008-04-05 19:40:20 -0500 (Sat, 05 Apr 2008)
New Revision: 4967

Modified:
   trunk/numpy/core/tests/test_numeric.py
   trunk/numpy/ma/tests/test_core.py
Log:
Add tests for ddof parameter in var/std [patch by Anne Archibald].


Modified: trunk/numpy/core/tests/test_numeric.py
===================================================================
--- trunk/numpy/core/tests/test_numeric.py	2008-04-05 22:34:51 UTC (rev 4966)
+++ trunk/numpy/core/tests/test_numeric.py	2008-04-06 00:40:20 UTC (rev 4967)
@@ -724,6 +724,21 @@
         assert_array_equal(x,array([inf,1]))
         assert_array_equal(y,array([0,inf]))
 
+class TestStdVar(NumpyTestCase):
+    def setUp(self):
+        self.A = array([1,-1,1,-1])
+        self.real_var = 1
+
+    def test_basic(self):
+        assert_almost_equal(var(self.A),self.real_var)
+        assert_almost_equal(std(self.A)**2,self.real_var)
+    def test_ddof1(self):
+        assert_almost_equal(var(self.A,ddof=1),self.real_var*len(self.A)/float(len(self.A)-1))
+        assert_almost_equal(std(self.A,ddof=1)**2,self.real_var*len(self.A)/float(len(self.A)-1))
+    def test_ddof2(self):
+        assert_almost_equal(var(self.A,ddof=2),self.real_var*len(self.A)/float(len(self.A)-2))
+        assert_almost_equal(std(self.A,ddof=2)**2,self.real_var*len(self.A)/float(len(self.A)-2))
+
 import sys
 if sys.version_info[:2] >= (2, 5):
     set_local_path()

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-04-05 22:34:51 UTC (rev 4966)
+++ trunk/numpy/ma/tests/test_core.py	2008-04-06 00:40:20 UTC (rev 4967)
@@ -1009,6 +1009,8 @@
         assert_equal(mXX.var(axis=3).shape,XX.var(axis=3).shape)
         assert_equal(mX.var().shape,X.var().shape)
         (mXvar0,mXvar1) = (mX.var(axis=0), mX.var(axis=1))
+        assert_almost_equal(mX.var(axis=None,ddof=2),mX.compressed().var(ddof=2))
+        assert_almost_equal(mX.std(axis=None,ddof=2),mX.compressed().std(ddof=2))
         for k in range(6):
             assert_almost_equal(mXvar1[k],mX[k].compressed().var())
             assert_almost_equal(mXvar0[k],mX[:,k].compressed().var())



More information about the Numpy-svn mailing list