summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-07-29 23:18:31 -0700
committerEric Wieser <wieser.eric@gmail.com>2018-07-29 23:18:31 -0700
commit766d82f85ac04ffd9ba32e0266bc270acfe7ed60 (patch)
tree3f2600b8dff13f264bf28eee6556e5ff13f264c2 /numpy/ma
parent083aedba2f49e1b490d3e122f5927f0718cf202c (diff)
downloadnumpy-766d82f85ac04ffd9ba32e0266bc270acfe7ed60.tar.gz
ENH: Make expand_dims work on subclasses
This allows np.ma.expand_dims to be removed
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py52
1 files changed, 1 insertions, 51 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 5bfa51b12..74edeb274 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -43,7 +43,7 @@ from numpy.lib.function_base import angle
from numpy.compat import (
getargspec, formatargspec, long, basestring, unicode, bytes
)
-from numpy import expand_dims as n_expand_dims
+from numpy import expand_dims
from numpy.core.multiarray import normalize_axis_index
from numpy.core.numeric import normalize_axis_tuple
@@ -6795,56 +6795,6 @@ def diag(v, k=0):
return output
-def expand_dims(x, axis):
- """
- Expand the shape of an array.
-
- Expands the shape of the array by including a new axis before the one
- specified by the `axis` parameter. This function behaves the same as
- `numpy.expand_dims` but preserves masked elements.
-
- See Also
- --------
- numpy.expand_dims : Equivalent function in top-level NumPy module.
-
- Examples
- --------
- >>> import numpy.ma as ma
- >>> x = ma.array([1, 2, 4])
- >>> x[1] = ma.masked
- >>> x
- masked_array(data = [1 -- 4],
- mask = [False True False],
- fill_value = 999999)
- >>> np.expand_dims(x, axis=0)
- array([[1, 2, 4]])
- >>> ma.expand_dims(x, axis=0)
- masked_array(data =
- [[1 -- 4]],
- mask =
- [[False True False]],
- fill_value = 999999)
-
- The same result can be achieved using slicing syntax with `np.newaxis`.
-
- >>> x[np.newaxis, :]
- masked_array(data =
- [[1 -- 4]],
- mask =
- [[False True False]],
- fill_value = 999999)
-
- """
- result = n_expand_dims(x, axis)
- if isinstance(x, MaskedArray):
- new_shape = result.shape
- result = x.view()
- result.shape = new_shape
- if result._mask is not nomask:
- result._mask.shape = new_shape
- return result
-
-
def left_shift(a, n):
"""
Shift the bits of an integer to the left.