[Scipy-svn] r2969 - trunk/Lib/sandbox/maskedarray

scipy-svn at scipy.org scipy-svn at scipy.org
Sun May 6 22:38:03 EDT 2007


Author: pierregm
Date: 2007-05-06 21:38:00 -0500 (Sun, 06 May 2007)
New Revision: 2969

Modified:
   trunk/Lib/sandbox/maskedarray/core.py
   trunk/Lib/sandbox/maskedarray/extras.py
Log:
core   : force var to return a masked array
extras : (flat)notmasked_contiguous: return a sequence of slices instead of the previous less useful (size,(start,end))
extras : dot now accepts 1D arrays.

Modified: trunk/Lib/sandbox/maskedarray/core.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/core.py	2007-05-05 21:18:43 UTC (rev 2968)
+++ trunk/Lib/sandbox/maskedarray/core.py	2007-05-07 02:38:00 UTC (rev 2969)
@@ -1651,7 +1651,7 @@
             cnt = self.count(axis=axis)
             danom = self.anom(axis=axis, dtype=dtype)
             danom *= danom
-            dvar = danom.sum(axis) / cnt
+            dvar = numeric.array(danom.sum(axis) / cnt).view(type(self))
             if axis is not None:
                 dvar._mask = mask_or(self._mask.all(axis), (cnt==1))
             return dvar
@@ -2634,7 +2634,7 @@
     from maskedarray.testutils import assert_equal, assert_array_equal
     marray = masked_array
     #
-    if 1:
+    if 0:
         x = masked_array([1,2])
         y = x * masked
         print y
@@ -2643,3 +2643,8 @@
         y = x + masked
         assert_equal(y.shape, x.shape)
         assert_equal(y._mask, [True, True])
+    #
+    if 1:
+        x = arange(10)
+        x[0] = masked
+        print dot(x,x)

Modified: trunk/Lib/sandbox/maskedarray/extras.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/extras.py	2007-05-05 21:18:43 UTC (rev 2968)
+++ trunk/Lib/sandbox/maskedarray/extras.py	2007-05-07 02:38:00 UTC (rev 2969)
@@ -435,8 +435,9 @@
     NB: The first argument is not conjugated.
     """
     #TODO: Works only with 2D arrays. There should be a way to get it to run with higher dimension
-    a = mask_rows(a)
-    b = mask_cols(b)
+    if (a.ndim == 2) and (b.ndim == 2):
+        a = mask_rows(a)
+        b = mask_cols(b)
     #
     d = numpy.dot(a.filled(0), b.filled(0))
     #
@@ -600,7 +601,7 @@
 
 def flatnotmasked_contiguous(a):
     """Finds contiguous unmasked data in a flattened masked array.
-    Returns a sorted sequence of tuples (size,(start index, end index)).
+    Returns a sorted sequence of slices (start index, end index).
     """
     m = getmask(a)
     if m is nomask:
@@ -611,13 +612,14 @@
     result = []
     for k, group in groupby(enumerate(unmasked), lambda (i,x):i-x):
         tmp = numpy.fromiter((g[1] for g in group), int_)
-        result.append((tmp.size, tuple(tmp[[0,-1]])))
+#        result.append((tmp.size, tuple(tmp[[0,-1]])))
+        result.append( slice(tmp[0],tmp[-1]) )
     result.sort()
     return result
 
 def notmasked_contiguous(a, axis=None):
     """Finds contiguous unmasked data in a masked array along the given axis.
-    Returns a sorted sequence of tuples (size,(start index, end index)).
+    Returns a sorted sequence of slices (start index, end index).
     Note: Only accepts 2D arrays at most.
     """
     a = asarray(a)
@@ -638,3 +640,10 @@
         result.append( flatnotmasked_contiguous(a[idx]) )
     return result
   
+################################################################################
+if __name__ == '__main__':
+    #
+    if 1:
+        x = arange(10)
+        x[0] = masked
+        print dot(x,x)
\ No newline at end of file




More information about the Scipy-svn mailing list