summaryrefslogtreecommitdiff
path: root/numpy/ma/extras.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2010-08-09 19:27:14 +0000
committerpierregm <pierregm@localhost>2010-08-09 19:27:14 +0000
commit3ab71ce374c3b35d4ce487e70249e73eb29fcce6 (patch)
treeaacf86bcd35fc3e8090281ee432654f840e793a2 /numpy/ma/extras.py
parent7b7bbc5541e046238ff680b9f3667f4d13174ca6 (diff)
downloadnumpy-3ab71ce374c3b35d4ce487e70249e73eb29fcce6.tar.gz
* fixed numpy.ma.extras.flatnotmasked_contiguous (bug #1576)
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r--numpy/ma/extras.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index 3aba7ad72..62e482f7b 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1644,16 +1644,14 @@ def flatnotmasked_contiguous(a):
"""
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 @@ def notmasked_contiguous(a, axis=None):
#
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