[Scipy-svn] r5393 - in trunk/scipy/stats: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Jan 8 07:37:12 EST 2009


Author: cdavid
Date: 2009-01-08 06:37:06 -0600 (Thu, 08 Jan 2009)
New Revision: 5393

Modified:
   trunk/scipy/stats/morestats.py
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_stats.py
Log:
Do not use stats.mean anymore anywhere in scipy.

Modified: trunk/scipy/stats/morestats.py
===================================================================
--- trunk/scipy/stats/morestats.py	2009-01-08 12:36:51 UTC (rev 5392)
+++ trunk/scipy/stats/morestats.py	2009-01-08 12:37:06 UTC (rev 5393)
@@ -332,7 +332,7 @@
     """
     N = len(data)
     y = boxcox(data,lmb)
-    my = stats.mean(y)
+    my = np.mean(y, axis=0)
     f = (lmb-1)*sum(log(data),axis=0)
     f -= N/2.0*log(sum((y-my)**2.0/N,axis=0))
     return f
@@ -499,7 +499,7 @@
     if not dist in ['norm','expon','gumbel','extreme1','logistic']:
         raise ValueError, "Invalid distribution."
     y = sort(x)
-    xbar = stats.mean(x)
+    xbar = np.mean(x, axis=0)
     N = len(y)
     if dist == 'norm':
         s = stats.std(x)
@@ -721,7 +721,7 @@
     if center == 'median':
         func = stats.median
     elif center == 'mean':
-        func = stats.mean
+        func = lambda x: np.mean(x, axis=0)
     else:
         func = stats.trim_mean
     for j in range(k):
@@ -737,7 +737,7 @@
     Zbari = zeros(k,'d')
     Zbar = 0.0
     for i in range(k):
-        Zbari[i] = stats.mean(Zij[i])
+        Zbari[i] = np.mean(Zij[i], axis=0)
         Zbar += Zbari[i]*Ni[i]
     Zbar /= Ntot
 
@@ -843,7 +843,7 @@
     if center == 'median':
         func = stats.median
     elif center == 'mean':
-        func = stats.mean
+        func = lambda x: np.mean(x, axis=0)
     else:
         func = stats.trim_mean
 
@@ -862,7 +862,7 @@
 
     # compute Aibar
     Aibar = _apply_func(a,g,sum) / Ni
-    anbar = stats.mean(a)
+    anbar = stats.mean(a, axis=0)
     varsq = stats.var(a)
 
     Xsq = sum(Ni*(asarray(Aibar)-anbar)**2.0,axis=0)/varsq
@@ -921,8 +921,8 @@
         evar = 0
 
     Ni = array([len(args[i]) for i in range(k)])
-    Mi = array([stats.mean(args[i]) for i in range(k)])
-    Vi = array([stats.var(args[i]) for i in range(k)])
+    Mi = array([np.mean(args[i], axis=0) for i in range(k)])
+    Vi = array([np.var(args[i]) for i in range(k)])
     Wi = Ni / Vi
     swi = sum(Wi,axis=0)
     N = sum(Ni,axis=0)
@@ -1068,7 +1068,7 @@
     """Compute the circular mean for samples assumed to be in the range [low to high]
     """
     ang = (samples - low)*2*pi / (high-low)
-    res = angle(stats.mean(exp(1j*ang)))
+    res = angle(np.mean(exp(1j*ang), axis=0))
     if (res < 0):
         res = res + 2*pi
     return res*(high-low)/2.0/pi + low
@@ -1077,7 +1077,7 @@
     """Compute the circular variance for samples assumed to be in the range [low to high]
     """
     ang = (samples - low)*2*pi / (high-low)
-    res = stats.mean(exp(1j*ang))
+    res = np.mean(exp(1j*ang), axis=0)
     V = 1-abs(res)
     return ((high-low)/2.0/pi)**2 * V
 
@@ -1085,7 +1085,7 @@
     """Compute the circular standard deviation for samples assumed to be in the range [low to high]
     """
     ang = (samples - low)*2*pi / (high-low)
-    res = stats.mean(exp(1j*ang))
+    res = np.mean(exp(1j*ang), axis=0)
     V = 1-abs(res)
     return ((high-low)/2.0/pi) * sqrt(V)
 

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2009-01-08 12:36:51 UTC (rev 5392)
+++ trunk/scipy/stats/stats.py	2009-01-08 12:37:06 UTC (rev 5393)
@@ -394,8 +394,6 @@
     return size / np.sum(1.0/a, axis)
 
 def mean(a, axis=0):
-    # fixme: This seems to be redundant with numpy.mean(,axis=0) or even
-    # the ndarray.mean() method.
     """Returns the arithmetic mean of m along the given dimension.
 
     That is: (x1 + x2 + .. + xn) / n
@@ -411,15 +409,13 @@
     all values in the array if axis=None. The return value will have a floating
     point dtype even if the input data are integers.
     """
-    warnings.warn("""\
+    raise DeprecationWarning("""\
 scipy.stats.mean is deprecated; please update your code to use numpy.mean.
 Please note that:
     - numpy.mean axis argument defaults to None, not 0
     - numpy.mean has a ddof argument to replace bias in a more general manner.
       scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
-axis=0, ddof=1).""", DeprecationWarning)
-    a, axis = _chk_asarray(a, axis)
-    return a.mean(axis)
+axis=0, ddof=1).""")
 
 def cmedian(a, numbins=1000):
     # fixme: numpy.median() always seems to be a better choice.
@@ -1261,7 +1257,7 @@
 an integer (the axis over which to operate)
 """
     a, axis = _chk_asarray(a, axis)
-    mn = np.expand_dims(mean(a, axis), axis)
+    mn = np.expand_dims(np.mean(a, axis), axis)
     deviations = a - mn
     n = a.shape[axis]
     svar = ss(deviations,axis) / float(n)
@@ -1284,7 +1280,7 @@
 Returns: array containing the value of (mean/stdev) along axis,
          or 0 when stdev=0
 """
-    m = mean(instack,axis)
+    m = np.mean(instack,axis)
     sd = samplestd(instack,axis)
     return np.where(sd == 0, 0, m/sd)
 
@@ -1303,7 +1299,7 @@
       axis=0, ddof=0), scipy.stats.var(a, bias=False) by var(x, axis=0,
       ddof=1).""", DeprecationWarning)
     a, axis = _chk_asarray(a, axis)
-    mn = np.expand_dims(mean(a,axis),axis)
+    mn = np.expand_dims(np.mean(a,axis),axis)
     deviations = a - mn
     n = a.shape[axis]
     vals = sum(abs(deviations)**2,axis)/(n-1.0)
@@ -1358,7 +1354,7 @@
 arrays > 1D.
 
 """
-    z = (score-mean(a,None)) / samplestd(a)
+    z = (score-np.mean(a,None)) / samplestd(a)
     return z
 
 
@@ -1368,7 +1364,7 @@
 computed relative to the passed array.
 
 """
-    mu = mean(a,None)
+    mu = np.mean(a,None)
     sigma = samplestd(a)
     return (array(a)-mu)/sigma
 
@@ -1780,8 +1776,8 @@
         x = asarray(args[0])
         y = asarray(args[1])
     n = len(x)
-    xmean = mean(x,None)
-    ymean = mean(y,None)
+    xmean = np.mean(x,None)
+    ymean = np.mean(y,None)
     xm,ym = x-xmean, y-ymean
     r_num = np.add.reduce(xm*ym)
     r_den = np.sqrt(ss(xm)*ss(ym))
@@ -1956,7 +1952,7 @@
     n2 = b.shape[axis]
     df = n1+n2-2
 
-    d = mean(a,axis) - mean(b,axis)
+    d = np.mean(a,axis) - np.mean(b,axis)
     svar = ((n1-1)*v1+(n2-1)*v2) / float(df)
 
     t = d/np.sqrt(svar*(1.0/n1 + 1.0/n2))

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:36:51 UTC (rev 5392)
+++ trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:37:06 UTC (rev 5393)
@@ -105,7 +105,7 @@
     """
 
     def test_meanX(self):
-        y = stats.mean(X)
+        y = np.mean(X)
         assert_almost_equal(y, 5.0)
 
     def test_stdX(self):
@@ -125,7 +125,7 @@
         assert_almost_equal(y, 2.1602468994692865)
 
     def test_meanZERO(self):
-        y = stats.mean(ZERO)
+        y = np.mean(ZERO)
         assert_almost_equal(y, 0.0)
 
     def test_stdZERO(self):
@@ -134,7 +134,7 @@
 
 ##    Really need to write these tests to handle missing values properly
 ##    def test_meanMISS(self):
-##        y = stats.mean(MISS)
+##        y = np.mean(MISS)
 ##        assert_almost_equal(y, 0.0)
 ##
 ##    def test_stdMISS(self):
@@ -142,7 +142,7 @@
 ##        assert_almost_equal(y, 0.0)
 
     def test_meanBIG(self):
-        y = stats.mean(BIG)
+        y = np.mean(BIG)
 
         assert_almost_equal(y, 99999995.00)
 
@@ -151,7 +151,7 @@
         assert_almost_equal(y, 2.738612788)
 
     def test_meanLITTLE(self):
-        y = stats.mean(LITTLE)
+        y = np.mean(LITTLE)
         assert_approx_equal(y, 0.999999950)
 
     def test_stdLITTLE(self):
@@ -159,7 +159,7 @@
         assert_approx_equal(y, 2.738612788e-8)
 
     def test_meanHUGE(self):
-        y = stats.mean(HUGE)
+        y = np.mean(HUGE)
         assert_approx_equal(y, 5.00000e+12)
 
     def test_stdHUGE(self):
@@ -167,7 +167,7 @@
         assert_approx_equal(y, 2.738612788e12)
 
     def test_meanTINY(self):
-        y = stats.mean(TINY)
+        y = np.mean(TINY)
         assert_almost_equal(y, 0.0)
 
     def test_stdTINY(self):
@@ -175,7 +175,7 @@
         assert_almost_equal(y, 0.0)
 
     def test_meanROUND(self):
-        y = stats.mean(ROUND)
+        y = np.mean(ROUND)
         assert_approx_equal(y, 4.500000000)
 
     def test_stdROUND(self):
@@ -595,11 +595,11 @@
         mn1 = 0.0
         for el in a:
             mn1 += el / float(Na)
-        assert_almost_equal(stats.mean(a),mn1,11)
+        assert_almost_equal(np.mean(a),mn1,11)
         mn2 = 0.0
         for el in af:
             mn2 += el / float(Naf)
-        assert_almost_equal(stats.mean(af),mn2,11)
+        assert_almost_equal(np.mean(af),mn2,11)
 
     def test_2d(self):
         a = [[1.0, 2.0, 3.0],
@@ -610,20 +610,19 @@
         mn1 = zeros(N2, dtype=float)
         for k in range(N1):
             mn1 += A[k,:] / N1
-        assert_almost_equal(stats.mean(a, axis=0), mn1, decimal=13)
-        assert_almost_equal(stats.mean(a), mn1, decimal=13)
+        assert_almost_equal(np.mean(a, axis=0), mn1, decimal=13)
         mn2 = zeros(N1, dtype=float)
         for k in range(N2):
             mn2 += A[:,k]
         mn2 /= N2
-        assert_almost_equal(stats.mean(a, axis=1), mn2, decimal=13)
+        assert_almost_equal(np.mean(a, axis=1), mn2, decimal=13)
 
     def test_ravel(self):
         a = rand(5,3,5)
         A = 0
         for val in ravel(a):
             A += val
-        assert_almost_equal(stats.mean(a,axis=None),A/(5*3.0*5))
+        assert_almost_equal(np.mean(a,axis=None),A/(5*3.0*5))
 
 class TestPercentile(TestCase):
     def setUp(self):
@@ -773,7 +772,7 @@
         not in R, so used
         (10-mean(testcase,axis=0))/sqrt(var(testcase)*3/4)
         """
-        y = stats.z(self.testcase,stats.mean(self.testcase))
+        y = stats.z(self.testcase,np.mean(self.testcase, axis=0))
         assert_almost_equal(y,0.0)
 
     def test_zs(self):




More information about the Scipy-svn mailing list