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

numpy-svn@scip... numpy-svn@scip...
Mon Jan 19 02:53:55 CST 2009


Author: pierregm
Date: 2009-01-19 02:53:53 -0600 (Mon, 19 Jan 2009)
New Revision: 6326

Modified:
   trunk/numpy/ma/core.py
Log:
* renamed FlatIter to MaskedIterator
* added __getitem__ to MaskedIterator


Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2009-01-17 21:24:13 UTC (rev 6325)
+++ trunk/numpy/ma/core.py	2009-01-19 08:53:53 UTC (rev 6326)
@@ -1464,10 +1464,11 @@
         return result
 #..........................................................
 
-class FlatIter(object):
+class MaskedIterator(object):
     "Define an interator."
     def __init__(self, ma):
         self.ma = ma
+        self.ma1d = ma.ravel()
         self.ma_iter = np.asarray(ma).flat
 
         if ma._mask is nomask:
@@ -1478,10 +1479,12 @@
     def __iter__(self):
         return self
 
+    def __getitem__(self, indx):
+        return self.ma1d.__getitem__(indx)
+
     ### This won't work is ravel makes a copy
     def __setitem__(self, index, value):
-        a = self.ma.ravel()
-        a[index] = value
+        self.ma1d[index] = value
 
     def next(self):
         "Returns the next element of the iterator."
@@ -2168,7 +2171,7 @@
         """Return a flat iterator.
 
         """
-        return FlatIter(self)
+        return MaskedIterator(self)
     #
     def _set_flat (self, value):
         """Set a flattened version of self to value.



More information about the Numpy-svn mailing list