[Numpy-svn] r8612 - trunk/numpy/ma

numpy-svn@scip... numpy-svn@scip...
Mon Aug 9 14:27:14 CDT 2010


Author: pierregm
Date: 2010-08-09 14:27:14 -0500 (Mon, 09 Aug 2010)
New Revision: 8612

Modified:
   trunk/numpy/ma/extras.py
Log:
* fixed numpy.ma.extras.flatnotmasked_contiguous (bug #1576)

Modified: trunk/numpy/ma/extras.py
===================================================================
--- trunk/numpy/ma/extras.py	2010-08-08 18:52:19 UTC (rev 8611)
+++ trunk/numpy/ma/extras.py	2010-08-09 19:27:14 UTC (rev 8612)
@@ -1644,16 +1644,14 @@
     """
     m = getmask(a)
     if m is nomask:
-        return (a.size, [0, -1])
-    unmasked = np.flatnonzero(~m)
-    if len(unmasked) == 0:
-        return None
+        return slice(0, a.size, None)
+    i = 0
     result = []
-    for (k, group) in itertools.groupby(enumerate(unmasked), lambda (i, x):i - x):
-        tmp = np.array([g[1] for g in group], int)
-#        result.append((tmp.size, tuple(tmp[[0,-1]])))
-        result.append(slice(tmp[0], tmp[-1]))
-    result.sort()
+    for (k, g) in itertools.groupby(m.ravel()):
+        n = len(list(g))
+        if not k:
+            result.append(slice(i, i + n))
+        i += n
     return result
 
 def notmasked_contiguous(a, axis=None):
@@ -1711,7 +1709,7 @@
     #
     for i in range(a.shape[other]):
         idx[other] = i
-        result.append(flatnotmasked_contiguous(a[idx]))
+        result.append(flatnotmasked_contiguous(a[idx]) or None)
     return result
 
 



More information about the Numpy-svn mailing list