[Scipy-svn] r6841 - trunk/scipy/ndimage

scipy-svn@scip... scipy-svn@scip...
Thu Oct 14 10:39:40 CDT 2010


Author: stefan
Date: 2010-10-14 10:39:40 -0500 (Thu, 14 Oct 2010)
New Revision: 6841

Modified:
   trunk/scipy/ndimage/measurements.py
Log:
ENH: ndimage: Smaller round-off error when computing variance.

Modified: trunk/scipy/ndimage/measurements.py
===================================================================
--- trunk/scipy/ndimage/measurements.py	2010-10-14 15:39:06 UTC (rev 6840)
+++ trunk/scipy/ndimage/measurements.py	2010-10-14 15:39:40 UTC (rev 6841)
@@ -279,7 +279,7 @@
 
     def single_group(vals):
         if centered:
-            vals_c = vals# - vals.mean()
+            vals_c = vals - vals.mean()
             return vals.size, vals.sum(), (vals_c * vals_c.conjugate()).sum()
         else:
             return vals.size, vals.sum()
@@ -301,7 +301,7 @@
 
     def _sum_centered(labels):
         means = sums / counts
-        centered_input = input# - means[labels]
+        centered_input = input - means[labels]
         return numpy.bincount(labels,
                               weights=(centered_input * \
                                        centered_input.conjugate()).ravel())
@@ -408,11 +408,9 @@
     none, all values where label is greater than zero are used.
     """
 
-    count, sum, sum_c = _stats(input, labels, index, centered=True)
-    mean = sum / numpy.asanyarray(count).astype(numpy.float)
-    mean2 = sum_c / numpy.asanyarray(count).astype(numpy.float)
+    count, sum, sum_c_sq = _stats(input, labels, index, centered=True)
 
-    return mean2 - (mean * mean.conjugate())
+    return sum_c_sq / np.asanyarray(count).astype(float)
 
 def standard_deviation(input, labels = None, index = None):
     """Calculate the standard deviation of the values of an array at labels.



More information about the Scipy-svn mailing list