[Numpy-svn] r5492 - in branches/1.1.x/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Jul 21 15:17:08 EDT 2008
Author: pierregm
Date: 2008-07-21 14:17:06 -0500 (Mon, 21 Jul 2008)
New Revision: 5492
Modified:
branches/1.1.x/numpy/ma/core.py
branches/1.1.x/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: branches/1.1.x/numpy/ma/core.py
===================================================================
--- branches/1.1.x/numpy/ma/core.py 2008-07-21 18:51:47 UTC (rev 5491)
+++ branches/1.1.x/numpy/ma/core.py 2008-07-21 19:17:06 UTC (rev 5492)
@@ -1867,7 +1867,7 @@
#
repeat = _arraymethod('repeat')
#
- def reshape (self, shape, order='C'):
+ def reshape (self, *shape, **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,
@@ -1892,11 +1892,12 @@
If you want to modify the shape in place, please use ``a.shape = s``
"""
- result = self._data.reshape(shape, order=order).view(type(self))
+ kwargs.update({'order':kwargs.get('order','C')})
+ result = self._data.reshape(*shape, **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(*shape, **kwargs)
return result
#
def resize(self, newshape, refcheck=True, order=False):
@@ -3426,7 +3427,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: branches/1.1.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.1.x/numpy/ma/tests/test_core.py 2008-07-21 18:51:47 UTC (rev 5491)
+++ branches/1.1.x/numpy/ma/tests/test_core.py 2008-07-21 19:17:06 UTC (rev 5492)
@@ -872,10 +872,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