diff options
author | Thomas Robitaille <thomas.robitaille@gmail.com> | 2012-11-20 11:51:59 +0100 |
---|---|---|
committer | Thomas Robitaille <thomas.robitaille@gmail.com> | 2012-11-20 11:51:59 +0100 |
commit | 2a43ed339f1350872207b9871ebdc3fbd0a68d26 (patch) | |
tree | aa9faa490d525007683b58d454304912acbe9db4 /numpy/ma | |
parent | 3e99f32b8e32fcb7bd16c7c4a3163e778d07cdc6 (diff) | |
download | numpy-2a43ed339f1350872207b9871ebdc3fbd0a68d26.tar.gz |
Added a `fill_value` keyword to `MaskedArray.view`, and clarify the behavior in the docstring.
Diffstat (limited to 'numpy/ma')
-rw-r--r-- | numpy/ma/core.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index a683e4151..fd49085d6 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -2852,7 +2852,16 @@ class MaskedArray(ndarray): return result - def view(self, dtype=None, type=None): + def view(self, dtype=None, type=None, fill_value=None): + """ + Return a view of the MaskedArray + + If `fill_value` is not specified, but `dtype` is specified, the + `fill_value` of the MaskedArray will be reset. If neither `fill_value` + nor `dtype` are specified, then the fill value is preserved. Finally, + if `fill_value` is specified, but `dtype` is not, the fill value is + set to the specified value. + """ if dtype is None: if type is None: output = ndarray.view(self) @@ -2882,10 +2891,13 @@ class MaskedArray(ndarray): pass # Make sure to reset the _fill_value if needed if getattr(output, '_fill_value', None) is not None: - if dtype is None: - pass # leave _fill_value as is + if fill_value is None: + if dtype is None: + pass # leave _fill_value as is + else: + output._fill_value = None else: - output._fill_value = None + output._fill_value = fill_value return output view.__doc__ = ndarray.view.__doc__ |