summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index b7ee4a797..f6e445c2f 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2684,6 +2684,8 @@ class MaskedArray(ndarray):
_defaultmask = nomask
_defaulthardmask = False
_baseclass = ndarray
+ # Maximum number of elements per axis used when printing an array.
+ _print_width = 100
def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
subok=True, ndmin=0, fill_value=None,
@@ -3710,8 +3712,19 @@ class MaskedArray(ndarray):
# convert to object array to make filled work
names = self.dtype.names
if names is None:
- res = self._data.astype("O")
- res.view(ndarray)[m] = f
+ data = self._data
+ mask = m
+ # For big arrays, to avoid a costly conversion to the
+ # object dtype, extract the corners before the conversion.
+ for axis in range(self.ndim):
+ if data.shape[axis] > self._print_width:
+ ind = self._print_width // 2
+ arr = np.split(data, (ind, -ind), axis=axis)
+ data = np.concatenate((arr[0], arr[2]), axis=axis)
+ arr = np.split(mask, (ind, -ind), axis=axis)
+ mask = np.concatenate((arr[0], arr[2]), axis=axis)
+ res = data.astype("O")
+ res.view(ndarray)[mask] = f
else:
rdtype = _recursive_make_descr(self.dtype, "O")
res = self._data.astype(rdtype)
@@ -4690,7 +4703,7 @@ class MaskedArray(ndarray):
See Also
--------
numpy.ma.dot : equivalent function
-
+
"""
return dot(self, b, out=out, strict=strict)