summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-01-07 22:34:51 +0000
committerpierregm <pierregm@localhost>2009-01-07 22:34:51 +0000
commitd94861c391c3411407da7244881f78e006ac3fb9 (patch)
tree6b69f23066b4ce3773318cb3bd8a71160de5d2fa /numpy/ma/core.py
parent949fe033fac5c6b555fd9b2b8212005cc5bfe1fd (diff)
downloadnumpy-d94861c391c3411407da7244881f78e006ac3fb9.tar.gz
* Renamed `torecords` to `toflex`, keeping `torecords` as an alias
* Introduced `fromflex`, to reconstruct a masked_array from the output of `toflex` (can’t `use fromrecords` as it would clash with `numpy.ma.mrecords.fromrecords`) * Fixed a bug in MaskedBinaryOperation (#979) (wrong array broadcasting)
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r--numpy/ma/core.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index a012b197e..cb3de4cf9 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -34,7 +34,7 @@ __all__ = ['MAError', 'MaskError', 'MaskType', 'MaskedArray',
'default_fill_value', 'diag', 'diagonal', 'divide', 'dump', 'dumps',
'empty', 'empty_like', 'equal', 'exp', 'expand_dims',
'fabs', 'flatten_mask', 'fmod', 'filled', 'floor', 'floor_divide',
- 'fix_invalid', 'frombuffer', 'fromfunction',
+ 'fix_invalid', 'frombuffer', 'fromflex', 'fromfunction',
'getdata','getmask', 'getmaskarray', 'greater', 'greater_equal',
'harden_mask', 'hypot',
'identity', 'ids', 'indices', 'inner', 'innerproduct',
@@ -623,8 +623,8 @@ class _MaskedBinaryOperation:
# Transforms to a (subclass of) MaskedArray if we don't have a scalar
if result.shape:
result = result.view(get_masked_subclass(a, b))
- result._mask = make_mask_none(result.shape)
- result._mask.flat = m
+ if m.any():
+ result._mask = mask_or(getmaskarray(a), getmaskarray(b))
if isinstance(a, MaskedArray):
result._update_from(a)
if isinstance(b, MaskedArray):
@@ -3603,7 +3603,7 @@ class MaskedArray(ndarray):
def tofile(self, fid, sep="", format="%s"):
raise NotImplementedError("Not implemented yet, sorry...")
- def torecords(self):
+ def toflex(self):
"""
Transforms a MaskedArray into a flexible-type array with two fields:
* the ``_data`` field stores the ``_data`` part of the array;
@@ -3648,6 +3648,7 @@ class MaskedArray(ndarray):
record['_data'] = self._data
record['_mask'] = self._mask
return record
+ torecords = toflex
#--------------------------------------------
# Pickling
def __getstate__(self):
@@ -4613,6 +4614,15 @@ def fromfile(file, dtype=float, count=-1, sep=''):
raise NotImplementedError("Not yet implemented. Sorry")
+def fromflex(fxarray):
+ """
+ Rebuilds a masked_array from a flexible-type array output by the '.torecord'
+ array
+ """
+ return masked_array(fxarray['_data'], mask=fxarray['_mask'])
+
+
+
class _convert2ma:
"""Convert functions from numpy to numpy.ma.