[Numpy-svn] r5493 - in trunk/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Jul 21 14:17:11 CDT 2008


Author: pierregm
Date: 2008-07-21 14:17:09 -0500 (Mon, 21 Jul 2008)
New Revision: 5493

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
core:
* Make sure that the .reshape method accepts a new shape as a list (and not as a tuple only)

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-07-21 19:17:06 UTC (rev 5492)
+++ trunk/numpy/ma/core.py	2008-07-21 19:17:09 UTC (rev 5493)
@@ -2038,7 +2038,7 @@
     #
     repeat = _arraymethod('repeat')
     #
-    def reshape (self, shape, order='C'):
+    def reshape (self, *s, **kwargs):
         """
     Returns a masked array containing the data of a, but with a new shape.
     The result is a view to the original array; if this is not possible,
@@ -2063,11 +2063,13 @@
     If you want to modify the shape in place, please use ``a.shape = s``
 
         """
-        result = self._data.reshape(shape, order=order).view(type(self))
+        print "SHAPE: %s" % str(s)
+        kwargs.update(order=kwargs.get('order','C'))
+        result = self._data.reshape(*s, **kwargs).view(type(self))
         result._update_from(self)
         mask = self._mask
         if mask is not nomask:
-            result._mask = mask.reshape(shape, order=order)
+            result._mask = mask.reshape(*s, **kwargs)
         return result
     #
     def resize(self, newshape, refcheck=True, order=False):
@@ -3626,7 +3628,8 @@
     try:
         return a.reshape(new_shape, order=order)
     except AttributeError:
-        return narray(a, copy=False).reshape(new_shape, order=order).view(MaskedArray)
+        _tmp = narray(a, copy=False).reshape(new_shape, order=order)
+        return _tmp.view(MaskedArray)
 
 def resize(x, new_shape):
     """Return a new array with the specified shape.

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-07-21 19:17:06 UTC (rev 5492)
+++ trunk/numpy/ma/tests/test_core.py	2008-07-21 19:17:09 UTC (rev 5493)
@@ -2150,10 +2150,18 @@
         b = a.reshape((5,2))
         assert_equal(b.shape, (5,2))
         assert(b.flags['C'])
+        # Try w/ arguments as list instead of tuple
+        b = a.reshape(5,2)
+        assert_equal(b.shape, (5,2))
+        assert(b.flags['C'])
         # Try w/ order
         b = a.reshape((5,2), order='F')
         assert_equal(b.shape, (5,2))
         assert(b.flags['F'])
+        # Try w/ order
+        b = a.reshape(5,2, order='F')
+        assert_equal(b.shape, (5,2))
+        assert(b.flags['F'])
         #
         c = np.reshape(a, (2,5))
         assert(isinstance(c, MaskedArray))



More information about the Numpy-svn mailing list