diff options
author | pierregm <pierregm@localhost> | 2008-07-21 19:17:09 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2008-07-21 19:17:09 +0000 |
commit | 923ef804b6ab66033f90b2cba0b410032798a418 (patch) | |
tree | 809ebdb69487ffc68809e60c3dfef73a9f0c1819 /numpy | |
parent | 70e9b4906838c7e8a44d4e58c57517df68671555 (diff) | |
download | numpy-923ef804b6ab66033f90b2cba0b410032798a418.tar.gz |
core:
* Make sure that the .reshape method accepts a new shape as a list (and not as a tuple only)
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 11 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 8 |
2 files changed, 15 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 0e6696ad5..178ffe1b6 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2038,7 +2038,7 @@ masked_%(name)s(data = %(data)s, # 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 @@ masked_%(name)s(data = %(data)s, 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 @@ def reshape(a, new_shape, order='C'): 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. diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index d84fbf7a3..d59428d58 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -2150,10 +2150,18 @@ class TestMaskedArrayFunctions(TestCase): 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)) |