def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,<EOL>subok=True, ndmin=<NUM_LIT:0>, fill_value=None,<EOL>keep_mask=True, hard_mask=None, shrink=True,<EOL>**options):

<EOL>_data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)<EOL>_baseclass = getattr(data, '<STR_LIT>', type(_data))<EOL>if isinstance(data, MaskedArray) and (data.shape != _data.shape):<EOL><INDENT>copy = True<EOL><DEDENT>if not isinstance(data, cls) or not subok:<EOL><INDENT>_data = ndarray.view(_data, cls)<EOL><DEDENT>else:<EOL><INDENT>_data = ndarray.view(_data, type(data))<EOL><DEDENT>if hasattr(data, '<STR_LIT>') and not isinstance(data, ndarray):<EOL><INDENT>_data._mask = data._mask<EOL>_sharedmask = True<EOL><DEDENT>names_ = _data.dtype.names or ()<EOL>if names_:<EOL><INDENT>mdtype = make_mask_descr(_data.dtype)<EOL><DEDENT>else:<EOL><INDENT>mdtype = MaskType<EOL><DEDENT>if mask is nomask:<EOL><INDENT>if not keep_mask:<EOL><INDENT>if shrink:<EOL><INDENT>_data._mask = nomask<EOL><DEDENT>else:<EOL><INDENT>_data._mask = np.zeros(_data.shape, dtype=mdtype)<EOL><DEDENT><DEDENT>elif isinstance(data, (tuple, list)):<EOL><INDENT>try:<EOL><INDENT>mask = np.array([getmaskarray(m) for m in data],<EOL>dtype=mdtype)<EOL><DEDENT>except ValueError:<EOL><INDENT>mask = nomask<EOL><DEDENT>if (mdtype == MaskType) and mask.any():<EOL><INDENT>_data._mask = mask<EOL>_data._sharedmask = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if copy:<EOL><INDENT>_data._mask = _data._mask.copy()<EOL>_data._sharedmask = False<EOL>if getmask(data) is not nomask:<EOL><INDENT>data._mask.shape = data.shape<EOL><DEDENT><DEDENT>else:<EOL><INDENT>_data._sharedmask = True<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>mask = np.array(mask, copy=copy, dtype=mdtype)<EOL><DEDENT>except TypeError:<EOL><INDENT>mask = np.array([tuple([m] * len(mdtype)) for m in mask],<EOL>dtype=mdtype)<EOL><DEDENT>if mask.shape != _data.shape:<EOL><INDENT>(nd, nm) = (_data.size, mask.size)<EOL>if nm == <NUM_LIT:1>:<EOL><INDENT>mask = np.resize(mask, _data.shape)<EOL><DEDENT>elif nm == nd:<EOL><INDENT>mask = np.reshape(mask, _data.shape)<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>" +"<STR_LIT>"<EOL>raise MaskError(msg % (nd, nm))<EOL><DEDENT>copy = True<EOL><DEDENT>if _data._mask is nomask:<EOL><INDENT>_data._mask = mask<EOL>_data._sharedmask = not copy<EOL><DEDENT>else:<EOL><INDENT>if not keep_mask:<EOL><INDENT>_data._mask = mask<EOL>_data._sharedmask = not copy<EOL><DEDENT>else:<EOL><INDENT>if names_:<EOL><INDENT>def _recursive_or(a, b):<EOL><INDENT>"<STR_LIT>"<EOL>for name in a.dtype.names:<EOL><INDENT>(af, bf) = (a[name], b[name])<EOL>if af.dtype.names:<EOL><INDENT>_recursive_or(af, bf)<EOL><DEDENT>else:<EOL><INDENT>af |= bf<EOL><DEDENT><DEDENT>return<EOL><DEDENT>_recursive_or(_data._mask, mask)<EOL><DEDENT>else:<EOL><INDENT>_data._mask = np.logical_or(mask, _data._mask)<EOL><DEDENT>_data._sharedmask = False<EOL><DEDENT><DEDENT><DEDENT>if fill_value is None:<EOL><INDENT>fill_value = getattr(data, '<STR_LIT>', None)<EOL><DEDENT>if fill_value is not None:<EOL><INDENT>_data._fill_value = _check_fill_value(fill_value, _data.dtype)<EOL><DEDENT>if hard_mask is None:<EOL><INDENT>_data._hardmask = getattr(data, '<STR_LIT>', False)<EOL><DEDENT>else:<EOL><INDENT>_data._hardmask = hard_mask<EOL><DEDENT>_data._baseclass = _baseclass<EOL>return _data<EOL>

Create a new masked array from scratch.

Notes
-----
A masked array can also be created by taking a .view(MaskedArray).


if obj is not None and isinstance(obj, ndarray):<EOL><INDENT>_baseclass = type(obj)<EOL><DEDENT>else:<EOL><INDENT>_baseclass = ndarray<EOL><DEDENT>_optinfo = {}<EOL>_optinfo.update(getattr(obj, '<STR_LIT>', {}))<EOL>_optinfo.update(getattr(obj, '<STR_LIT>', {}))<EOL>if not isinstance(obj, MaskedArray):<EOL><INDENT>_optinfo.update(getattr(obj, '<STR_LIT>', {}))<EOL><DEDENT>_dict = dict(_fill_value=getattr(obj, '<STR_LIT>', None),<EOL>_hardmask=getattr(obj, '<STR_LIT>', False),<EOL>_sharedmask=getattr(obj, '<STR_LIT>', False),<EOL>_isfield=getattr(obj, '<STR_LIT>', False),<EOL>_baseclass=getattr(obj, '<STR_LIT>', _baseclass),<EOL>_optinfo=_optinfo,<EOL>_basedict=_optinfo)<EOL>self.__dict__.update(_dict)<EOL>self.__dict__.update(_optinfo)<EOL>return<EOL>


<EOL>self._update_from(obj)<EOL>if isinstance(obj, ndarray):<EOL><INDENT>if obj.dtype.names:<EOL><INDENT>_mask = getattr(obj, '<STR_LIT>',<EOL>make_mask_none(obj.shape, obj.dtype))<EOL><DEDENT>else:<EOL><INDENT>_mask = getattr(obj, '<STR_LIT>', nomask)<EOL><DEDENT>if (obj.__array_interface__["<STR_LIT:data>"][<NUM_LIT:0>]<EOL>!= self.__array_interface__["<STR_LIT:data>"][<NUM_LIT:0>]):<EOL><INDENT>_mask = _mask.copy()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>_mask = nomask<EOL><DEDENT>self._mask = _mask<EOL>if self._mask is not nomask:<EOL><INDENT>try:<EOL><INDENT>self._mask.shape = self.shape<EOL><DEDENT>except ValueError:<EOL><INDENT>self._mask = nomask<EOL><DEDENT>except (TypeError, AttributeError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if self.dtype.names:<EOL><INDENT>if self._fill_value is None:<EOL><INDENT>self._fill_value = _check_fill_value(None, self.dtype)<EOL><DEDENT><DEDENT>return<EOL>


def __array_wrap__(self, obj, context=None):

result = obj.view(type(self))<EOL>result._update_from(self)<EOL>if context is not None:<EOL><INDENT>result._mask = result._mask.copy()<EOL>(func, args, _) = context<EOL>m = reduce(mask_or, [getmaskarray(arg) for arg in args])<EOL>domain = ufunc_domain.get(func, None)<EOL>if domain is not None:<EOL><INDENT>if len(args) > <NUM_LIT:2>:<EOL><INDENT>d = filled(reduce(domain, args), True)<EOL><DEDENT>else:<EOL><INDENT>d = filled(domain(*args), True)<EOL><DEDENT>try:<EOL><INDENT>fill_value = ufunc_fills[func][-<NUM_LIT:1>]<EOL><DEDENT>except TypeError:<EOL><INDENT>fill_value = ufunc_fills[func]<EOL><DEDENT>except KeyError:<EOL><INDENT>fill_value = self.fill_value<EOL><DEDENT>result = result.copy()<EOL>np.copyto(result, fill_value, where=d)<EOL>if m is nomask:<EOL><INDENT>if d is not nomask:<EOL><INDENT>m = d<EOL><DEDENT><DEDENT>else:<EOL><INDENT>m = (m | d)<EOL><DEDENT><DEDENT>if result.shape == () and m:<EOL><INDENT>return masked<EOL><DEDENT>else:<EOL><INDENT>result._mask = m<EOL>result._sharedmask = False<EOL><DEDENT><DEDENT>return result<EOL>

Special hook for ufuncs.
Wraps the numpy array and sets the mask according to context.


def view(self, dtype=None, type=None, fill_value=None):

if dtype is None:<EOL><INDENT>if type is None:<EOL><INDENT>output = ndarray.view(self)<EOL><DEDENT>else:<EOL><INDENT>output = ndarray.view(self, type)<EOL><DEDENT><DEDENT>elif type is None:<EOL><INDENT>try:<EOL><INDENT>if issubclass(dtype, ndarray):<EOL><INDENT>output = ndarray.view(self, dtype)<EOL>dtype = None<EOL><DEDENT>else:<EOL><INDENT>output = ndarray.view(self, dtype)<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>output = ndarray.view(self, dtype)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output = ndarray.view(self, dtype, type)<EOL><DEDENT>if (getattr(output, '<STR_LIT>', nomask) is not nomask):<EOL><INDENT>if dtype is None:<EOL><INDENT>dtype = output.dtype<EOL><DEDENT>mdtype = make_mask_descr(dtype)<EOL>output._mask = self._mask.view(mdtype, ndarray)<EOL>try:<EOL><INDENT>output._mask.shape = output.shape<EOL><DEDENT>except (AttributeError, TypeError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if getattr(output, '<STR_LIT>', None) is not None:<EOL><INDENT>if fill_value is None:<EOL><INDENT>if dtype is None:<EOL><INDENT>pass <EOL><DEDENT>else:<EOL><INDENT>output._fill_value = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output.fill_value = fill_value<EOL><DEDENT><DEDENT>return output<EOL>

Return a view of the MaskedArray data

Parameters
----------
dtype : data-type or ndarray sub-class, optional
    Data-type descriptor of the returned view, e.g., float32 or int16.
    The default, None, results in the view having the same data-type
    as `a`. As with ``ndarray.view``, dtype can also be specified as
    an ndarray sub-class, which then specifies the type of the
    returned object (this is equivalent to setting the ``type``
    parameter).
type : Python type, optional
    Type of the returned view, e.g., ndarray or matrix.  Again, the
    default None results in type preservation.

Notes
-----

``a.view()`` is used two different ways:

``a.view(some_dtype)`` or ``a.view(dtype=some_dtype)`` constructs a view
of the array's memory with a different data-type.  This can cause a
reinterpretation of the bytes of memory.

``a.view(ndarray_subclass)`` or ``a.view(type=ndarray_subclass)`` just
returns an instance of `ndarray_subclass` that looks at the same array
(same shape, dtype, etc.)  This does not cause a reinterpretation of the
memory.

If `fill_value` is not specified, but `dtype` is specified (and is not
an ndarray sub-class), the `fill_value` of the MaskedArray will be
reset. If neither `fill_value` nor `dtype` are specified (or if
`dtype` is an ndarray sub-class), 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.

For ``a.view(some_dtype)``, if ``some_dtype`` has a different number of
bytes per entry than the previous dtype (for example, converting a
regular array to a structured array), then the behavior of the view
cannot be predicted just from the superficial appearance of ``a`` (shown
by ``print(a)``). It also depends on exactly how ``a`` is stored in
memory. Therefore if ``a`` is C-ordered versus fortran-ordered, versus
defined as a slice or transpose, etc., the view may give different
results.


newtype = np.dtype(newtype)<EOL>output = self._data.astype(newtype).view(type(self))<EOL>output._update_from(self)<EOL>names = output.dtype.names<EOL>if names is None:<EOL><INDENT>output._mask = self._mask.astype(bool)<EOL><DEDENT>else:<EOL><INDENT>if self._mask is nomask:<EOL><INDENT>output._mask = nomask<EOL><DEDENT>else:<EOL><INDENT>output._mask = self._mask.astype([(n, bool) for n in names])<EOL><DEDENT><DEDENT>if self._fill_value is not None:<EOL><INDENT>output._fill_value = _check_fill_value(self._fill_value, newtype)<EOL><DEDENT>return output<EOL>

Returns a copy of the MaskedArray cast to given newtype.

Returns
-------
output : MaskedArray
    A copy of self cast to input newtype.
    The returned record shape matches self.shape.

Examples
--------
>>> x = np.ma.array([[1,2,3.1],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1.0 -- 3.1]
 [-- 5.0 --]
 [7.0 -- 9.0]]
>>> print x.astype(int32)
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]


<EOL><INDENT>if getmask(indx) is not nomask:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise IndexError(msg)<EOL><DEDENT><DEDENT>_data = ndarray.view(self, ndarray)<EOL>dout = ndarray.__getitem__(_data, indx)<EOL>_mask = self._mask<EOL>if not getattr(dout, '<STR_LIT>', False):<EOL><INDENT>if isinstance(dout, np.void):<EOL><INDENT>mask = _mask[indx]<EOL>dout = mvoid(dout, mask=mask, hardmask=self._hardmask)<EOL><DEDENT>elif _mask is not nomask and _mask[indx]:<EOL><INDENT>return masked<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dout = dout.view(type(self))<EOL>dout._update_from(self)<EOL>if isinstance(indx, basestring):<EOL><INDENT>if self._fill_value is not None:<EOL><INDENT>dout._fill_value = self._fill_value[indx]<EOL><DEDENT>dout._isfield = True<EOL><DEDENT>if _mask is not nomask:<EOL><INDENT>dout._mask = _mask[indx]<EOL>dout._sharedmask = True<EOL>Note: Don'<STR_LIT>'ll take too long...<EOL><DEDENT><DEDENT>return dout<EOL>

x.__getitem__(y) <==> x[y]

        Return the item described by i, as a masked array.


if self is masked:<EOL><INDENT>raise MaskError('<STR_LIT>')<EOL>

x.__setitem__(i, y) <==> x[i]=y

        Set item described by index. If value is masked, masks those
        locations.


return self.__getitem__(slice(i, j))<EOL>

x.__getslice__(i, j) <==> x[i:j]

        Return the slice described by (i, j).  The use of negative
        indices is not supported.


self.__setitem__(slice(i, j), value)<EOL>

x.__setslice__(i, j, value) <==> x[i:j]=value

    Set the slice (i,j) of a to value. If value is masked, mask
    those locations.


def __setmask__(self, mask, copy=False):

idtype = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>current_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>if mask is masked:<EOL><INDENT>mask = True<EOL><DEDENT>if (current_mask is nomask):<EOL><INDENT>if mask is nomask:<EOL><INDENT>return<EOL><DEDENT>current_mask = self._mask = make_mask_none(self.shape, idtype)<EOL><DEDENT>if idtype.names is None:<EOL><INDENT>if self._hardmask:<EOL><INDENT>current_mask |= mask<EOL><DEDENT>elif isinstance(mask, (int, float, np.bool_, np.number)):<EOL><INDENT>current_mask[...] = mask<EOL><DEDENT>else:<EOL><INDENT>current_mask.flat = mask<EOL><DEDENT><DEDENT>else:<EOL><INDENT>mdtype = current_mask.dtype<EOL>mask = np.array(mask, copy=False)<EOL>if not mask.ndim:<EOL><INDENT>if mask.dtype.kind == '<STR_LIT:b>':<EOL><INDENT>mask = np.array(tuple([mask.item()]*len(mdtype)),<EOL>dtype=mdtype)<EOL><DEDENT>else:<EOL><INDENT>mask = mask.astype(mdtype)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>mask = np.array(mask, copy=copy, dtype=mdtype)<EOL><DEDENT>except TypeError:<EOL><INDENT>mask = np.array([tuple([m] * len(mdtype)) for m in mask],<EOL>dtype=mdtype)<EOL><DEDENT><DEDENT>if self._hardmask:<EOL><INDENT>for n in idtype.names:<EOL><INDENT>current_mask[n] |= mask[n]<EOL><DEDENT><DEDENT>elif isinstance(mask, (int, float, np.bool_, np.number)):<EOL><INDENT>current_mask[...] = mask<EOL><DEDENT>else:<EOL><INDENT>current_mask.flat = mask<EOL><DEDENT><DEDENT>if current_mask.shape:<EOL><INDENT>current_mask.shape = self.shape<EOL><DEDENT>return<EOL>


<EOL><INDENT>return self._mask.reshape(self.shape)<EOL><DEDENT>return self._mask<EOL>


_mask = ndarray.__getattribute__(self, '<STR_LIT>').view(ndarray)<EOL>if _mask.dtype.names is None:<EOL><INDENT>return _mask<EOL><DEDENT>return np.all(flatten_structured_array(_mask), axis= -<NUM_LIT:1>)<EOL>

Return the mask of the records.
A record is masked when all the fields are masked.


raise NotImplementedError("<STR_LIT>")<EOL>

Return the mask of the records.
    A record is masked when all the fields are masked.


self._hardmask = True<EOL>return self<EOL>

Force the mask to hard.

Whether the mask of a masked array is hard or soft is determined by
its `hardmask` property. `harden_mask` sets `hardmask` to True.

See Also
--------
hardmask


self._hardmask = False<EOL>return self<EOL>

Force the mask to soft.

Whether the mask of a masked array is hard or soft is determined by
its `hardmask` property. `soften_mask` sets `hardmask` to False.

See Also
--------
hardmask


if self._sharedmask:<EOL><INDENT>self._mask = self._mask.copy()<EOL>self._sharedmask = False<EOL><DEDENT>return self<EOL>

Copy the mask and set the sharedmask flag to False.

Whether the mask is shared between masked arrays can be seen from
the `sharedmask` property. `unshare_mask` ensures the mask is not shared.
A copy of the mask is only made if it was shared.

See Also
--------
sharedmask


m = self._mask<EOL>if m.ndim and not m.any():<EOL><INDENT>self._mask = nomask<EOL><DEDENT>return self<EOL>

Reduce a mask to nomask when possible.

Parameters
----------
None

Returns
-------
None

Examples
--------
>>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4)
>>> x.mask
array([[False, False],
       [False, False]], dtype=bool)
>>> x.shrink_mask()
>>> x.mask
False


return ndarray.view(self, self._baseclass)<EOL>

Return the current data, as a view of the original
        underlying data.


return MaskedIterator(self)<EOL>


y = self.ravel()<EOL>y[:] = value<EOL>

Set a flattened version of self to value.


if self._fill_value is None:<EOL><INDENT>self._fill_value = _check_fill_value(None, self.dtype)<EOL><DEDENT>return self._fill_value[()]<EOL>

Return the filling value of the masked array.

Returns
-------
fill_value : scalar
    The filling value.

Examples
--------
>>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
...     np.ma.array([0, 1], dtype=dt).get_fill_value()
...
999999
999999
1e+20
(1e+20+0j)

>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.get_fill_value()
-inf


target = _check_fill_value(value, self.dtype)<EOL>_fill_value = self._fill_value<EOL>if _fill_value is None:<EOL><INDENT>self._fill_value = target<EOL><DEDENT>else:<EOL><INDENT>_fill_value[()] = target<EOL><DEDENT>

Set the filling value of the masked array.

Parameters
----------
value : scalar, optional
    The new filling value. Default is None, in which case a default
    based on the data type is used.

See Also
--------
ma.set_fill_value : Equivalent function.

Examples
--------
>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.fill_value
-inf
>>> x.set_fill_value(np.pi)
>>> x.fill_value
3.1415926535897931

Reset to default:

>>> x.set_fill_value()
>>> x.fill_value
1e+20


m = self._mask<EOL>if m is nomask:<EOL><INDENT>return self._data<EOL><DEDENT>if fill_value is None:<EOL><INDENT>fill_value = self.fill_value<EOL><DEDENT>else:<EOL><INDENT>fill_value = _check_fill_value(fill_value, self.dtype)<EOL><DEDENT>if self is masked_singleton:<EOL><INDENT>return np.asanyarray(fill_value)<EOL><DEDENT>if m.dtype.names:<EOL><INDENT>result = self._data.copy('<STR_LIT>')<EOL>_recursive_filled(result, self._mask, fill_value)<EOL><DEDENT>elif not m.any():<EOL><INDENT>return self._data<EOL><DEDENT>else:<EOL><INDENT>result = self._data.copy('<STR_LIT>')<EOL>try:<EOL><INDENT>np.copyto(result, fill_value, where=m)<EOL><DEDENT>except (TypeError, AttributeError):<EOL><INDENT>fill_value = narray(fill_value, dtype=object)<EOL>d = result.astype(object)<EOL>result = np.choose(m, (d, fill_value))<EOL><DEDENT>except IndexError:<EOL><INDENT>if self._data.shape:<EOL><INDENT>raise<EOL><DEDENT>elif m:<EOL><INDENT>result = np.array(fill_value, dtype=self.dtype)<EOL><DEDENT>else:<EOL><INDENT>result = self._data<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

Return a copy of self, with masked values filled with a given value.

Parameters
----------
fill_value : scalar, optional
    The value to use for invalid entries (None by default).
    If None, the `fill_value` attribute of the array is used instead.

Returns
-------
filled_array : ndarray
    A copy of ``self`` with invalid entries replaced by *fill_value*
    (be it the function argument or the attribute of ``self``.

Notes
-----
The result is **not** a MaskedArray!

Examples
--------
>>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999)
>>> x.filled()
array([1, 2, -999, 4, -999])
>>> type(x.filled())
<type 'numpy.ndarray'>

Subclassing is preserved. This means that if the data part of the masked
array is a matrix, `filled` returns a matrix:

>>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.filled()
matrix([[     1, 999999],
        [999999,      4]])


data = ndarray.ravel(self._data)<EOL>if self._mask is not nomask:<EOL><INDENT>data = data.compress(np.logical_not(ndarray.ravel(self._mask)))<EOL><DEDENT>return data<EOL>

Return all the non-masked data as a 1-D array.

Returns
-------
data : ndarray
    A new `ndarray` holding the non-masked data is returned.

Notes
-----
The result is **not** a MaskedArray!

Examples
--------
>>> x = np.ma.array(np.arange(5), mask=[0]*2 + [1]*3)
>>> x.compressed()
array([0, 1])
>>> type(x.compressed())
<type 'numpy.ndarray'>


def compress(self, condition, axis=None, out=None):

<EOL>(_data, _mask) = (self._data, self._mask)<EOL>condition = np.array(condition, copy=False, subok=False)<EOL>_new = _data.compress(condition, axis=axis, out=out).view(type(self))<EOL>_new._update_from(self)<EOL>if _mask is not nomask:<EOL><INDENT>_new._mask = _mask.compress(condition, axis=axis)<EOL><DEDENT>return _new<EOL>

Return `a` where condition is ``True``.

If condition is a `MaskedArray`, missing values are considered
as ``False``.

Parameters
----------
condition : var
    Boolean 1-d array selecting which entries to return. If len(condition)
    is less than the size of a along the axis, then output is truncated
    to length of condition array.
axis : {None, int}, optional
    Axis along which the operation must be performed.
out : {None, ndarray}, optional
    Alternative output array in which to place the result. It must have
    the same shape as the expected output but the type will be cast if
    necessary.

Returns
-------
result : MaskedArray
    A :class:`MaskedArray` object.

Notes
-----
Please note the difference with :meth:`compressed` !
The output of :meth:`compress` has a mask, the output of
:meth:`compressed` does not.

Examples
--------
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]
>>> x.compress([1, 0, 1])
masked_array(data = [1 3],
      mask = [False False],
      fill_value=999999)

>>> x.compress([1, 0, 1], axis=1)
masked_array(data =
 [[1 3]
 [-- --]
 [7 9]],
      mask =
 [[False False]
 [ True  True]
 [False False]],
      fill_value=999999)


if masked_print_option.enabled():<EOL><INDENT>f = masked_print_option<EOL>if self is masked:<EOL><INDENT>return str(f)<EOL><DEDENT>m = self._mask<EOL>if m is nomask:<EOL><INDENT>res = self._data<EOL><DEDENT>else:<EOL><INDENT>if m.shape == ():<EOL><INDENT>if m.dtype.names:<EOL><INDENT>m = m.view((bool, len(m.dtype)))<EOL>if m.any():<EOL><INDENT>return str(tuple((f if _m else _d) for _d, _m in<EOL>zip(self._data.tolist(), m)))<EOL><DEDENT>else:<EOL><INDENT>return str(self._data)<EOL><DEDENT><DEDENT>elif m:<EOL><INDENT>return str(f)<EOL><DEDENT>else:<EOL><INDENT>return str(self._data)<EOL><DEDENT><DEDENT>names = self.dtype.names<EOL>if names is None:<EOL><INDENT>res = self._data.astype("<STR_LIT:O>")<EOL>res.view(ndarray)[m] = f<EOL><DEDENT>else:<EOL><INDENT>rdtype = _recursive_make_descr(self.dtype, "<STR_LIT:O>")<EOL>res = self._data.astype(rdtype)<EOL>_recursive_printoption(res, m, f)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>res = self.filled(self.fill_value)<EOL><DEDENT>return str(res)<EOL>


n = len(self.shape)<EOL>if self._baseclass is np.ndarray:<EOL><INDENT>name = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>name = self._baseclass.__name__<EOL><DEDENT>parameters = dict(name=name, nlen="<STR_LIT:U+0020>" * len(name),<EOL>data=str(self), mask=str(self._mask),<EOL>fill=str(self.fill_value), dtype=str(self.dtype))<EOL>if self.dtype.names:<EOL><INDENT>if n <= <NUM_LIT:1>:<EOL><INDENT>return _print_templates['<STR_LIT>'] % parameters<EOL><DEDENT>return _print_templates['<STR_LIT>'] % parameters<EOL><DEDENT>elif n <= <NUM_LIT:1>:<EOL><INDENT>return _print_templates['<STR_LIT>'] % parameters<EOL><DEDENT>return _print_templates['<STR_LIT>'] % parameters<EOL>


if self is masked:<EOL><INDENT>return masked<EOL><DEDENT>omask = getattr(other, '<STR_LIT>', nomask)<EOL>if omask is nomask:<EOL><INDENT>check = ndarray.__eq__(self.filled(<NUM_LIT:0>), other)<EOL>try:<EOL><INDENT>check = check.view(type(self))<EOL>check._mask = self._mask<EOL><DEDENT>except AttributeError:<EOL><INDENT>return check<EOL><DEDENT><DEDENT>else:<EOL><INDENT>odata = filled(other, <NUM_LIT:0>)<EOL>check = ndarray.__eq__(self.filled(<NUM_LIT:0>), odata).view(type(self))<EOL>if self._mask is nomask:<EOL><INDENT>check._mask = omask<EOL><DEDENT>else:<EOL><INDENT>mask = mask_or(self._mask, omask)<EOL>if mask.dtype.names:<EOL><INDENT>if mask.size > <NUM_LIT:1>:<EOL><INDENT>axis = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>axis = None<EOL><DEDENT>try:<EOL><INDENT>mask = mask.view((bool_, len(self.dtype))).all(axis)<EOL><DEDENT>except ValueError:<EOL><INDENT>mask = np.all([[f[n].all() for n in mask.dtype.names]<EOL>for f in mask], axis=axis)<EOL><DEDENT><DEDENT>check._mask = mask<EOL><DEDENT><DEDENT>return check<EOL>

Check whether other equals self elementwise


if self is masked:<EOL><INDENT>return masked<EOL><DEDENT>omask = getattr(other, '<STR_LIT>', nomask)<EOL>if omask is nomask:<EOL><INDENT>check = ndarray.__ne__(self.filled(<NUM_LIT:0>), other)<EOL>try:<EOL><INDENT>check = check.view(type(self))<EOL>check._mask = self._mask<EOL><DEDENT>except AttributeError:<EOL><INDENT>return check<EOL><DEDENT><DEDENT>else:<EOL><INDENT>odata = filled(other, <NUM_LIT:0>)<EOL>check = ndarray.__ne__(self.filled(<NUM_LIT:0>), odata).view(type(self))<EOL>if self._mask is nomask:<EOL><INDENT>check._mask = omask<EOL><DEDENT>else:<EOL><INDENT>mask = mask_or(self._mask, omask)<EOL>if mask.dtype.names:<EOL><INDENT>if mask.size > <NUM_LIT:1>:<EOL><INDENT>axis = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>axis = None<EOL><DEDENT>try:<EOL><INDENT>mask = mask.view((bool_, len(self.dtype))).all(axis)<EOL><DEDENT>except ValueError:<EOL><INDENT>mask = np.all([[f[n].all() for n in mask.dtype.names]<EOL>for f in mask], axis=axis)<EOL><DEDENT><DEDENT>check._mask = mask<EOL><DEDENT><DEDENT>return check<EOL>

Check whether other doesn't equal self elementwise


return add(self, other)<EOL>

Add other to self, and return a new masked array.


return add(self, other)<EOL>


return subtract(self, other)<EOL>

Subtract other to self, and return a new masked array.


return subtract(other, self)<EOL>


return multiply(self, other)<EOL>

Multiply other by self, and return a new masked array.


return multiply(self, other)<EOL>


return divide(self, other)<EOL>

Divide other into self, and return a new masked array.


return true_divide(self, other)<EOL>


return true_divide(other, self)<EOL>


return floor_divide(self, other)<EOL>


return floor_divide(other, self)<EOL>


return power(self, other)<EOL>

Raise self to the power other, masking the potential NaNs/Infs


return power(other, self)<EOL>


m = getmask(other)<EOL>if self._mask is nomask:<EOL><INDENT>if m is not nomask and m.any():<EOL><INDENT>self._mask = make_mask_none(self.shape, self.dtype)<EOL>self._mask += m<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if m is not nomask:<EOL><INDENT>self._mask += m<EOL><DEDENT><DEDENT>ndarray.__iadd__(self._data, np.where(self._mask, <NUM_LIT:0>, getdata(other)))<EOL>return self<EOL>


m = getmask(other)<EOL>if self._mask is nomask:<EOL><INDENT>if m is not nomask and m.any():<EOL><INDENT>self._mask = make_mask_none(self.shape, self.dtype)<EOL>self._mask += m<EOL><DEDENT><DEDENT>elif m is not nomask:<EOL><INDENT>self._mask += m<EOL><DEDENT>ndarray.__isub__(self._data, np.where(self._mask, <NUM_LIT:0>, getdata(other)))<EOL>return self<EOL>


m = getmask(other)<EOL>if self._mask is nomask:<EOL><INDENT>if m is not nomask and m.any():<EOL><INDENT>self._mask = make_mask_none(self.shape, self.dtype)<EOL>self._mask += m<EOL><DEDENT><DEDENT>elif m is not nomask:<EOL><INDENT>self._mask += m<EOL><DEDENT>ndarray.__imul__(self._data, np.where(self._mask, <NUM_LIT:1>, getdata(other)))<EOL>return self<EOL>


other_data = getdata(other)<EOL>dom_mask = _DomainSafeDivide().__call__(self._data, other_data)<EOL>other_mask = getmask(other)<EOL>new_mask = mask_or(other_mask, dom_mask)<EOL>if dom_mask.any():<EOL><INDENT>(_, fval) = ufunc_fills[np.divide]<EOL>other_data = np.where(dom_mask, fval, other_data)<EOL>


other_data = getdata(other)<EOL>dom_mask = _DomainSafeDivide().__call__(self._data, other_data)<EOL>other_mask = getmask(other)<EOL>new_mask = mask_or(other_mask, dom_mask)<EOL>if dom_mask.any():<EOL><INDENT>(_, fval) = ufunc_fills[np.floor_divide]<EOL>other_data = np.where(dom_mask, fval, other_data)<EOL>


other_data = getdata(other)<EOL>dom_mask = _DomainSafeDivide().__call__(self._data, other_data)<EOL>other_mask = getmask(other)<EOL>new_mask = mask_or(other_mask, dom_mask)<EOL>if dom_mask.any():<EOL><INDENT>(_, fval) = ufunc_fills[np.true_divide]<EOL>other_data = np.where(dom_mask, fval, other_data)<EOL>


other_data = getdata(other)<EOL>other_mask = getmask(other)<EOL>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>ndarray.__ipow__(self._data, np.where(self._mask, <NUM_LIT:1>, other_data))<EOL><DEDENT>invalid = np.logical_not(np.isfinite(self._data))<EOL>if invalid.any():<EOL><INDENT>if self._mask is not nomask:<EOL><INDENT>self._mask |= invalid<EOL><DEDENT>else:<EOL><INDENT>self._mask = invalid<EOL><DEDENT>np.copyto(self._data, self.fill_value, where=invalid)<EOL><DEDENT>new_mask = mask_or(other_mask, invalid)<EOL>self._mask = mask_or(self._mask, new_mask)<EOL>return self<EOL>

Raise self to the power other, in place.


if self.size > <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>elif self._mask:<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL>return np.nan<EOL><DEDENT>return float(self.item())<EOL>


if self.size > <NUM_LIT:1>:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>elif self._mask:<EOL><INDENT>raise MaskError('<STR_LIT>')<EOL><DEDENT>return int(self.item())<EOL>


result = self._data.imag.view(type(self))<EOL>result.__setmask__(self._mask)<EOL>return result<EOL>

Return the imaginary part of the masked array.

The returned array is a view on the imaginary part of the `MaskedArray`
whose `get_imag` method is called.

Parameters
----------
None

Returns
-------
result : MaskedArray
    The imaginary part of the masked array.

See Also
--------
get_real, real, imag

Examples
--------
>>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
>>> x.get_imag()
masked_array(data = [1.0 -- 1.6],
             mask = [False  True False],
       fill_value = 1e+20)


result = self._data.real.view(type(self))<EOL>result.__setmask__(self._mask)<EOL>return result<EOL>

Return the real part of the masked array.

The returned array is a view on the real part of the `MaskedArray`
whose `get_real` method is called.

Parameters
----------
None

Returns
-------
result : MaskedArray
    The real part of the masked array.

See Also
--------
get_imag, real, imag

Examples
--------
>>> x = np.ma.array([1+1.j, -2j, 3.45+1.6j], mask=[False, True, False])
>>> x.get_real()
masked_array(data = [1.0 -- 3.45],
             mask = [False  True False],
       fill_value = 1e+20)


m = self._mask<EOL>s = self.shape<EOL>if m is nomask:<EOL><INDENT>if axis is None:<EOL><INDENT>return self.size<EOL><DEDENT>else:<EOL><INDENT>n = s[axis]<EOL>t = list(s)<EOL>del t[axis]<EOL>return np.full(t, n, dtype=np.intp)<EOL><DEDENT><DEDENT>n1 = np.size(m, axis)<EOL>n2 = np.sum(m, axis=axis, dtype=np.intp)<EOL>if axis is None:<EOL><INDENT>return (n1 - n2)<EOL><DEDENT>else:<EOL><INDENT>return narray(n1 - n2)<EOL><DEDENT>

Count the non-masked elements of the array along the given axis.

Parameters
----------
axis : int, optional
    Axis along which to count the non-masked elements. If `axis` is
    `None`, all non-masked elements are counted.

Returns
-------
result : int or ndarray
    If `axis` is `None`, an integer count is returned. When `axis` is
    not `None`, an array with shape determined by the lengths of the
    remaining axes, is returned.

See Also
--------
count_masked : Count masked elements in array or along a given axis.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.arange(6).reshape((2, 3))
>>> a[1, :] = ma.masked
>>> a
masked_array(data =
 [[0 1 2]
 [-- -- --]],
             mask =
 [[False False False]
 [ True  True  True]],
       fill_value = 999999)
>>> a.count()
3

When the `axis` keyword is specified an array of appropriate size is
returned.

>>> a.count(axis=0)
array([1, 1, 1])
>>> a.count(axis=1)
array([3, 0])


r = ndarray.ravel(self._data).view(type(self))<EOL>r._update_from(self)<EOL>if self._mask is not nomask:<EOL><INDENT>r._mask = ndarray.ravel(self._mask).reshape(r.shape)<EOL><DEDENT>else:<EOL><INDENT>r._mask = nomask<EOL><DEDENT>return r<EOL>

Returns a 1D version of self, as a view.

Returns
-------
MaskedArray
    Output view is of shape ``(self.size,)`` (or
    ``(np.ma.product(self.shape),)``).

Examples
--------
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]
>>> print x.ravel()
[1 -- 3 -- 5 -- 7 -- 9]


kwargs.update(order=kwargs.get('<STR_LIT>', '<STR_LIT:C>'))<EOL>result = self._data.reshape(*s, **kwargs).view(type(self))<EOL>result._update_from(self)<EOL>mask = self._mask<EOL>if mask is not nomask:<EOL><INDENT>result._mask = mask.reshape(*s, **kwargs)<EOL><DEDENT>return result<EOL>

Give a new shape to the array without changing its data.

Returns a masked array containing the same data, but with a new shape.
The result is a view on the original array; if this is not possible, a
ValueError is raised.

Parameters
----------
shape : int or tuple of ints
    The new shape should be compatible with the original shape. If an
    integer is supplied, then the result will be a 1-D array of that
    length.
order : {'C', 'F'}, optional
    Determines whether the array data should be viewed as in C
    (row-major) or FORTRAN (column-major) order.

Returns
-------
reshaped_array : array
    A new view on the array.

See Also
--------
reshape : Equivalent function in the masked array module.
numpy.ndarray.reshape : Equivalent method on ndarray object.
numpy.reshape : Equivalent function in the NumPy module.

Notes
-----
The reshaping operation cannot guarantee that a copy will not be made,
to modify the shape in place, use ``a.shape = s``

Examples
--------
>>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1])
>>> print x
[[-- 2]
 [3 --]]
>>> x = x.reshape((4,1))
>>> print x
[[--]
 [2]
 [3]
 [--]]


def resize(self, newshape, refcheck=True, order=False):

<EOL><INDENT>try:<EOL><INDENT>ndarray.resize(self, newshape, refcheck=refcheck)<EOL>if self.mask is not nomask:<EOL><INDENT>self._mask.resize(newshape, refcheck=refcheck)<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return None<EOL><DEDENT>errmsg = "<STR_LIT>""<STR_LIT>""<STR_LIT>"<EOL>raise ValueError(errmsg)<EOL>

.. warning::

    This method does nothing, except raise a ValueError exception. A
    masked array does not own its data and therefore cannot safely be
    resized in place. Use the `numpy.ma.resize` function instead.

This method is difficult to implement safely and may be deprecated in
future releases of NumPy.


def put(self, indices, values, mode='<STR_LIT>'):

m = self._mask<EOL>if self._hardmask and self._mask is not nomask:<EOL><INDENT>mask = self._mask[indices]<EOL>indices = narray(indices, copy=False)<EOL>values = narray(values, copy=False, subok=True)<EOL>values.resize(indices.shape)<EOL>indices = indices[~mask]<EOL>values = values[~mask]<EOL><DEDENT>self._data.put(indices, values, mode=mode)<EOL>if m is nomask:<EOL><INDENT>m = getmask(values)<EOL><DEDENT>else:<EOL><INDENT>m = m.copy()<EOL>if getmask(values) is nomask:<EOL><INDENT>m.put(indices, False, mode=mode)<EOL><DEDENT>else:<EOL><INDENT>m.put(indices, values._mask, mode=mode)<EOL><DEDENT>m = make_mask(m, copy=False, shrink=True)<EOL><DEDENT>self._mask = m<EOL>

Set storage-indexed locations to corresponding values.

Sets self._data.flat[n] = values[n] for each n in indices.
If `values` is shorter than `indices` then it will repeat.
If `values` has some masked values, the initial mask is updated
in consequence, else the corresponding values are unmasked.

Parameters
----------
indices : 1-D array_like
    Target indices, interpreted as integers.
values : array_like
    Values to place in self._data copy at target indices.
mode : {'raise', 'wrap', 'clip'}, optional
    Specifies how out-of-bounds indices will behave.
    'raise' : raise an error.
    'wrap' : wrap around.
    'clip' : clip to the range.

Notes
-----
`values` can be a scalar or length 1 array.

Examples
--------
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]
>>> x.put([0,4,8],[10,20,30])
>>> print x
[[10 -- 3]
 [-- 20 --]
 [7 -- 30]]

>>> x.put(4,999)
>>> print x
[[10 -- 3]
 [-- 999 --]
 [7 -- 30]]


if self._mask is nomask:<EOL><INDENT>return (self.ctypes.data, id(nomask))<EOL><DEDENT>return (self.ctypes.data, self._mask.ctypes.data)<EOL>

Return the addresses of the data and mask areas.

Parameters
----------
None

Examples
--------
>>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1])
>>> x.ids()
(166670640, 166659832)

If the array has no mask, the address of `nomask` is returned. This address
is typically not close to the data in memory:

>>> x = np.ma.array([1, 2, 3])
>>> x.ids()
(166691080, 3083169284L)


return self.flags['<STR_LIT>']<EOL>

Return a boolean indicating whether the data is contiguous.

Parameters
----------
None

Examples
--------
>>> x = np.ma.array([1, 2, 3])
>>> x.iscontiguous()
True

`iscontiguous` returns one of the flags of the masked array:

>>> x.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False


mask = _check_mask_axis(self._mask, axis)<EOL>if out is None:<EOL><INDENT>d = self.filled(True).all(axis=axis).view(type(self))<EOL>if d.ndim:<EOL><INDENT>d.__setmask__(mask)<EOL><DEDENT>elif mask:<EOL><INDENT>return masked<EOL><DEDENT>return d<EOL><DEDENT>self.filled(True).all(axis=axis, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>if out.ndim or mask:<EOL><INDENT>out.__setmask__(mask)<EOL><DEDENT><DEDENT>return out<EOL>

Check if all of the elements of `a` are true.

Performs a :func:`logical_and` over the given axis and returns the result.
Masked values are considered as True during computation.
For convenience, the output array is masked where ALL the values along the
current axis are masked: if the output would have been a scalar and that
all the values are masked, then the output is `masked`.

Parameters
----------
axis : {None, integer}
    Axis to perform the operation over.
    If None, perform over flattened array.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

See Also
--------
all : equivalent function

Examples
--------
>>> np.ma.array([1,2,3]).all()
True
>>> a = np.ma.array([1,2,3], mask=True)
>>> (a.all() is np.ma.masked)
True


mask = _check_mask_axis(self._mask, axis)<EOL>if out is None:<EOL><INDENT>d = self.filled(False).any(axis=axis).view(type(self))<EOL>if d.ndim:<EOL><INDENT>d.__setmask__(mask)<EOL><DEDENT>elif mask:<EOL><INDENT>d = masked<EOL><DEDENT>return d<EOL><DEDENT>self.filled(False).any(axis=axis, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>if out.ndim or mask:<EOL><INDENT>out.__setmask__(mask)<EOL><DEDENT><DEDENT>return out<EOL>

Check if any of the elements of `a` are true.

Performs a logical_or over the given axis and returns the result.
Masked values are considered as False during computation.

Parameters
----------
axis : {None, integer}
    Axis to perform the operation over.
    If None, perform over flattened array and return a scalar.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

See Also
--------
any : equivalent function


return narray(self.filled(<NUM_LIT:0>), copy=False).nonzero()<EOL>

Return the indices of unmasked elements that are not zero.

Returns a tuple of arrays, one for each dimension, containing the
indices of the non-zero elements in that dimension. The corresponding
non-zero values can be obtained with::

    a[a.nonzero()]

To group the indices by element, rather than dimension, use
instead::

    np.transpose(a.nonzero())

The result of this is always a 2d array, with a row for each non-zero
element.

Parameters
----------
None

Returns
-------
tuple_of_arrays : tuple
    Indices of elements that are non-zero.

See Also
--------
numpy.nonzero :
    Function operating on ndarrays.
flatnonzero :
    Return indices that are non-zero in the flattened version of the input
    array.
ndarray.nonzero :
    Equivalent ndarray method.
count_nonzero :
    Counts the number of non-zero elements in the input array.

Examples
--------
>>> import numpy.ma as ma
>>> x = ma.array(np.eye(3))
>>> x
masked_array(data =
 [[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]],
      mask =
 False,
      fill_value=1e+20)
>>> x.nonzero()
(array([0, 1, 2]), array([0, 1, 2]))

Masked elements are ignored.

>>> x[1, 1] = ma.masked
>>> x
masked_array(data =
 [[1.0 0.0 0.0]
 [0.0 -- 0.0]
 [0.0 0.0 1.0]],
      mask =
 [[False False False]
 [False  True False]
 [False False False]],
      fill_value=1e+20)
>>> x.nonzero()
(array([0, 2]), array([0, 2]))

Indices can also be grouped by element.

>>> np.transpose(x.nonzero())
array([[0, 0],
       [2, 2]])

A common use for ``nonzero`` is to find the indices of an array, where
a condition is True.  Given an array `a`, the condition `a` > 3 is a
boolean array and since False is interpreted as 0, ma.nonzero(a > 3)
yields the indices of the `a` where the condition is true.

>>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
>>> a > 3
masked_array(data =
 [[False False False]
 [ True  True  True]
 [ True  True  True]],
      mask =
 False,
      fill_value=999999)
>>> ma.nonzero(a > 3)
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))

The ``nonzero`` method of the condition array can also be called.

>>> (a > 3).nonzero()
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))


def trace(self, offset=<NUM_LIT:0>, axis1=<NUM_LIT:0>, axis2=<NUM_LIT:1>, dtype=None, out=None):

<EOL>m = self._mask<EOL>if m is nomask:<EOL><INDENT>result = super(MaskedArray, self).trace(offset=offset, axis1=axis1,<EOL>axis2=axis2, out=out)<EOL>return result.astype(dtype)<EOL><DEDENT>else:<EOL><INDENT>D = self.diagonal(offset=offset, axis1=axis1, axis2=axis2)<EOL>return D.astype(dtype).filled(<NUM_LIT:0>).sum(axis=None, out=out)<EOL><DEDENT>


def sum(self, axis=None, dtype=None, out=None):

_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>newmask = _check_mask_axis(_mask, axis)<EOL>if out is None:<EOL><INDENT>result = self.filled(<NUM_LIT:0>).sum(axis, dtype=dtype)<EOL>rndim = getattr(result, '<STR_LIT>', <NUM_LIT:0>)<EOL>if rndim:<EOL><INDENT>result = result.view(type(self))<EOL>result.__setmask__(newmask)<EOL><DEDENT>elif newmask:<EOL><INDENT>result = masked<EOL><DEDENT>return result<EOL><DEDENT>result = self.filled(<NUM_LIT:0>).sum(axis, dtype=dtype, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>outmask = getattr(out, '<STR_LIT>', nomask)<EOL>if (outmask is nomask):<EOL><INDENT>outmask = out._mask = make_mask_none(out.shape)<EOL><DEDENT>outmask.flat = newmask<EOL><DEDENT>return out<EOL>

Return the sum of the array elements over the given axis.
Masked elements are set to 0 internally.

Parameters
----------
axis : {None, -1, int}, optional
    Axis along which the sum is computed. The default
    (`axis` = None) is to compute over the flattened array.
dtype : {None, dtype}, optional
    Determines the type of the returned array and of the accumulator
    where the elements are summed. If dtype has the value None and
    the type of a is an integer type of precision less than the default
    platform integer, then the default platform integer precision is
    used.  Otherwise, the dtype is the same as that of a.
out :  {None, ndarray}, optional
    Alternative output array in which to place the result. It must
    have the same shape and buffer length as the expected output
    but the type will be cast if necessary.

Returns
-------
sum_along_axis : MaskedArray or scalar
    An array with the same shape as self, with the specified
    axis removed.   If self is a 0-d array, or if `axis` is None, a scalar
    is returned.  If an output array is specified, a reference to
    `out` is returned.

Examples
--------
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]
>>> print x.sum()
25
>>> print x.sum(axis=1)
[4 5 16]
>>> print x.sum(axis=0)
[8 5 12]
>>> print type(x.sum(axis=0, dtype=np.int64)[0])
<type 'numpy.int64'>


def cumsum(self, axis=None, dtype=None, out=None):

result = self.filled(<NUM_LIT:0>).cumsum(axis=axis, dtype=dtype, out=out)<EOL>if out is not None:<EOL><INDENT>if isinstance(out, MaskedArray):<EOL><INDENT>out.__setmask__(self.mask)<EOL><DEDENT>return out<EOL><DEDENT>result = result.view(type(self))<EOL>result.__setmask__(self._mask)<EOL>return result<EOL>

Return the cumulative sum of the elements along the given axis.
The cumulative sum is calculated over the flattened array by
default, otherwise over the specified axis.

Masked values are set to 0 internally during the computation.
However, their position is saved, and the result will be masked at
the same locations.

Parameters
----------
axis : {None, -1, int}, optional
    Axis along which the sum is computed. The default (`axis` = None) is to
    compute over the flattened array. `axis` may be negative, in which case
    it counts from the   last to the first axis.
dtype : {None, dtype}, optional
    Type of the returned array and of the accumulator in which the
    elements are summed.  If `dtype` is not specified, it defaults
    to the dtype of `a`, unless `a` has an integer dtype with a
    precision less than that of the default platform integer.  In
    that case, the default platform integer is used.
out : ndarray, optional
    Alternative output array in which to place the result. It must
    have the same shape and buffer length as the expected output
    but the type will be cast if necessary.

Returns
-------
cumsum : ndarray.
    A new array holding the result is returned unless ``out`` is
    specified, in which case a reference to ``out`` is returned.

Notes
-----
The mask is lost if `out` is not a valid :class:`MaskedArray` !

Arithmetic is modular when using integer types, and no error is
raised on overflow.

Examples
--------
>>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0])
>>> print marr.cumsum()
[0 1 3 -- -- -- 9 16 24 33]


def prod(self, axis=None, dtype=None, out=None):

_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>newmask = _check_mask_axis(_mask, axis)<EOL>if out is None:<EOL><INDENT>result = self.filled(<NUM_LIT:1>).prod(axis, dtype=dtype)<EOL>rndim = getattr(result, '<STR_LIT>', <NUM_LIT:0>)<EOL>if rndim:<EOL><INDENT>result = result.view(type(self))<EOL>result.__setmask__(newmask)<EOL><DEDENT>elif newmask:<EOL><INDENT>result = masked<EOL><DEDENT>return result<EOL><DEDENT>result = self.filled(<NUM_LIT:1>).prod(axis, dtype=dtype, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>outmask = getattr(out, '<STR_LIT>', nomask)<EOL>if (outmask is nomask):<EOL><INDENT>outmask = out._mask = make_mask_none(out.shape)<EOL><DEDENT>outmask.flat = newmask<EOL><DEDENT>return out<EOL>

Return the product of the array elements over the given axis.
Masked elements are set to 1 internally for computation.

Parameters
----------
axis : {None, int}, optional
    Axis over which the product is taken. If None is used, then the
    product is over all the array elements.
dtype : {None, dtype}, optional
    Determines the type of the returned array and of the accumulator
    where the elements are multiplied. If ``dtype`` has the value ``None``
    and the type of a is an integer type of precision less than the default
    platform integer, then the default platform integer precision is
    used.  Otherwise, the dtype is the same as that of a.
out : {None, array}, optional
    Alternative output array in which to place the result. It must have
    the same shape as the expected output but the type will be cast if
    necessary.

Returns
-------
product_along_axis : {array, scalar}, see dtype parameter above.
    Returns an array whose shape is the same as a with the specified
    axis removed. Returns a 0d array when a is 1d or axis=None.
    Returns a reference to the specified output array if specified.

See Also
--------
prod : equivalent function

Notes
-----
Arithmetic is modular when using integer types, and no error is raised
on overflow.

Examples
--------
>>> np.prod([1.,2.])
2.0
>>> np.prod([1.,2.], dtype=np.int32)
2
>>> np.prod([[1.,2.],[3.,4.]])
24.0
>>> np.prod([[1.,2.],[3.,4.]], axis=1)
array([  2.,  12.])


def cumprod(self, axis=None, dtype=None, out=None):

result = self.filled(<NUM_LIT:1>).cumprod(axis=axis, dtype=dtype, out=out)<EOL>if out is not None:<EOL><INDENT>if isinstance(out, MaskedArray):<EOL><INDENT>out.__setmask__(self._mask)<EOL><DEDENT>return out<EOL><DEDENT>result = result.view(type(self))<EOL>result.__setmask__(self._mask)<EOL>return result<EOL>

Return the cumulative product of the elements along the given axis.
The cumulative product is taken over the flattened array by
default, otherwise over the specified axis.

Masked values are set to 1 internally during the computation.
However, their position is saved, and the result will be masked at
the same locations.

Parameters
----------
axis : {None, -1, int}, optional
    Axis along which the product is computed. The default
    (`axis` = None) is to compute over the flattened array.
dtype : {None, dtype}, optional
    Determines the type of the returned array and of the accumulator
    where the elements are multiplied. If ``dtype`` has the value ``None``
    and the type of ``a`` is an integer type of precision less than the
    default platform integer, then the default platform integer precision
    is used.  Otherwise, the dtype is the same as that of ``a``.
out : ndarray, optional
    Alternative output array in which to place the result. It must
    have the same shape and buffer length as the expected output
    but the type will be cast if necessary.

Returns
-------
cumprod : ndarray
    A new array holding the result is returned unless out is specified,
    in which case a reference to out is returned.

Notes
-----
The mask is lost if `out` is not a valid MaskedArray !

Arithmetic is modular when using integer types, and no error is
raised on overflow.


def mean(self, axis=None, dtype=None, out=None):

if self._mask is nomask:<EOL><INDENT>result = super(MaskedArray, self).mean(axis=axis, dtype=dtype)<EOL><DEDENT>else:<EOL><INDENT>dsum = self.sum(axis=axis, dtype=dtype)<EOL>cnt = self.count(axis=axis)<EOL>if cnt.shape == () and (cnt == <NUM_LIT:0>):<EOL><INDENT>result = masked<EOL><DEDENT>else:<EOL><INDENT>result = dsum * <NUM_LIT:1.> / cnt<EOL><DEDENT><DEDENT>if out is not None:<EOL><INDENT>out.flat = result<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>outmask = getattr(out, '<STR_LIT>', nomask)<EOL>if (outmask is nomask):<EOL><INDENT>outmask = out._mask = make_mask_none(out.shape)<EOL><DEDENT>outmask.flat = getattr(result, '<STR_LIT>', nomask)<EOL><DEDENT>return out<EOL><DEDENT>return result<EOL>

Returns the average of the array elements.

Masked entries are ignored.
The average is taken over the flattened array by default, otherwise over
the specified axis. Refer to `numpy.mean` for the full documentation.

Parameters
----------
a : array_like
    Array containing numbers whose mean is desired. If `a` is not an
    array, a conversion is attempted.
axis : int, optional
    Axis along which the means are computed. The default is to compute
    the mean of the flattened array.
dtype : dtype, optional
    Type to use in computing the mean. For integer inputs, the default
    is float64; for floating point, inputs it is the same as the input
    dtype.
out : ndarray, optional
    Alternative output array in which to place the result. It must have
    the same shape as the expected output but the type will be cast if
    necessary.

Returns
-------
mean : ndarray, see dtype parameter above
    If `out=None`, returns a new array containing the mean values,
    otherwise a reference to the output array is returned.

See Also
--------
numpy.ma.mean : Equivalent function.
numpy.mean : Equivalent function on non-masked arrays.
numpy.ma.average: Weighted average.

Examples
--------
>>> a = np.ma.array([1,2,3], mask=[False, False, True])
>>> a
masked_array(data = [1 2 --],
             mask = [False False  True],
       fill_value = 999999)
>>> a.mean()
1.5


m = self.mean(axis, dtype)<EOL>if not axis:<EOL><INDENT>return (self - m)<EOL><DEDENT>else:<EOL><INDENT>return (self - expand_dims(m, axis))<EOL><DEDENT>

Compute the anomalies (deviations from the arithmetic mean)
along the given axis.

Returns an array of anomalies, with the same shape as the input and
where the arithmetic mean is computed along the given axis.

Parameters
----------
axis : int, optional
    Axis over which the anomalies are taken.
    The default is to use the mean of the flattened array as reference.
dtype : dtype, optional
    Type to use in computing the variance. For arrays of integer type
     the default is float32; for arrays of float types it is the same as
     the array type.

See Also
--------
mean : Compute the mean of the array.

Examples
--------
>>> a = np.ma.array([1,2,3])
>>> a.anom()
masked_array(data = [-1.  0.  1.],
             mask = False,
       fill_value = 1e+20)


def round(self, decimals=<NUM_LIT:0>, out=None):

result = self._data.round(decimals=decimals, out=out).view(type(self))<EOL>result._mask = self._mask<EOL>result._update_from(self)<EOL>if out is None:<EOL><INDENT>return result<EOL><DEDENT>if isinstance(out, MaskedArray):<EOL><INDENT>out.__setmask__(self._mask)<EOL><DEDENT>return out<EOL>

Return an array rounded a to the given number of decimals.

Refer to `numpy.around` for full documentation.

See Also
--------
numpy.around : equivalent function


def argsort(self, axis=None, kind='<STR_LIT>', order=None, fill_value=None):

if fill_value is None:<EOL><INDENT>fill_value = default_fill_value(self)<EOL><DEDENT>d = self.filled(fill_value).view(ndarray)<EOL>return d.argsort(axis=axis, kind=kind, order=order)<EOL>

Return an ndarray of indices that sort the array along the
specified axis.  Masked values are filled beforehand to
`fill_value`.

Parameters
----------
axis : int, optional
    Axis along which to sort.  The default is -1 (last axis).
    If None, the flattened array is used.
fill_value : var, optional
    Value used to fill the array before sorting.
    The default is the `fill_value` attribute of the input array.
kind : {'quicksort', 'mergesort', 'heapsort'}, optional
    Sorting algorithm.
order : list, optional
    When `a` is an array with fields defined, this argument specifies
    which fields to compare first, second, etc.  Not all fields need be
    specified.

Returns
-------
index_array : ndarray, int
    Array of indices that sort `a` along the specified axis.
    In other words, ``a[index_array]`` yields a sorted `a`.

See Also
--------
sort : Describes sorting algorithms used.
lexsort : Indirect stable sort with multiple keys.
ndarray.sort : Inplace sort.

Notes
-----
See `sort` for notes on the different sorting algorithms.

Examples
--------
>>> a = np.ma.array([3,2,1], mask=[False, False, True])
>>> a
masked_array(data = [3 2 --],
             mask = [False False  True],
       fill_value = 999999)
>>> a.argsort()
array([1, 0, 2])


def argmin(self, axis=None, fill_value=None, out=None):

if fill_value is None:<EOL><INDENT>fill_value = minimum_fill_value(self)<EOL><DEDENT>d = self.filled(fill_value).view(ndarray)<EOL>return d.argmin(axis, out=out)<EOL>

Return array of indices to the minimum values along the given axis.

Parameters
----------
axis : {None, integer}
    If None, the index is into the flattened array, otherwise along
    the specified axis
fill_value : {var}, optional
    Value used to fill in the masked values.  If None, the output of
    minimum_fill_value(self._data) is used instead.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

Returns
-------
{ndarray, scalar}
    If multi-dimension input, returns a new ndarray of indices to the
    minimum values along the given axis.  Otherwise, returns a scalar
    of index to the minimum values along the given axis.

Examples
--------
>>> x = np.ma.array(arange(4), mask=[1,1,0,0])
>>> x.shape = (2,2)
>>> print x
[[-- --]
 [2 3]]
>>> print x.argmin(axis=0, fill_value=-1)
[0 0]
>>> print x.argmin(axis=0, fill_value=9)
[1 1]


def argmax(self, axis=None, fill_value=None, out=None):

if fill_value is None:<EOL><INDENT>fill_value = maximum_fill_value(self._data)<EOL><DEDENT>d = self.filled(fill_value).view(ndarray)<EOL>return d.argmax(axis, out=out)<EOL>

Returns array of indices of the maximum values along the given axis.
Masked values are treated as if they had the value fill_value.

Parameters
----------
axis : {None, integer}
    If None, the index is into the flattened array, otherwise along
    the specified axis
fill_value : {var}, optional
    Value used to fill in the masked values.  If None, the output of
    maximum_fill_value(self._data) is used instead.
out : {None, array}, optional
    Array into which the result can be placed. Its type is preserved
    and it must be of the right shape to hold the output.

Returns
-------
index_array : {integer_array}

Examples
--------
>>> a = np.arange(6).reshape(2,3)
>>> a.argmax()
5
>>> a.argmax(0)
array([1, 1, 1])
>>> a.argmax(1)
array([2, 2])


def sort(self, axis= -<NUM_LIT:1>, kind='<STR_LIT>', order=None,<EOL>endwith=True, fill_value=None):

if self._mask is nomask:<EOL><INDENT>ndarray.sort(self, axis=axis, kind=kind, order=order)<EOL><DEDENT>else:<EOL><INDENT>if self is masked:<EOL><INDENT>return self<EOL><DEDENT>if fill_value is None:<EOL><INDENT>if endwith:<EOL><INDENT>if np.issubdtype(self.dtype, np.floating):<EOL><INDENT>filler = np.nan<EOL><DEDENT>else:<EOL><INDENT>filler = minimum_fill_value(self)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filler = maximum_fill_value(self)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filler = fill_value<EOL><DEDENT>sidx = self.filled(filler).argsort(axis=axis, kind=kind,<EOL>order=order)<EOL>if self.ndim == <NUM_LIT:1>:<EOL><INDENT>idx = sidx<EOL><DEDENT>else:<EOL><INDENT>idx = np.meshgrid(*[np.arange(x) for x in self.shape], sparse=True,<EOL>indexing='<STR_LIT>')<EOL>idx[axis] = sidx<EOL><DEDENT>tmp_mask = self._mask[idx].flat<EOL>tmp_data = self._data[idx].flat<EOL>self._data.flat = tmp_data<EOL>self._mask.flat = tmp_mask<EOL><DEDENT>return<EOL>

Sort the array, in-place

Parameters
----------
a : array_like
    Array to be sorted.
axis : int, optional
    Axis along which to sort. If None, the array is flattened before
    sorting. The default is -1, which sorts along the last axis.
kind : {'quicksort', 'mergesort', 'heapsort'}, optional
    Sorting algorithm. Default is 'quicksort'.
order : list, optional
    When `a` is a structured array, this argument specifies which fields
    to compare first, second, and so on.  This list does not need to
    include all of the fields.
endwith : {True, False}, optional
    Whether missing values (if any) should be forced in the upper indices
    (at the end of the array) (True) or lower indices (at the beginning).
    When the array contains unmasked values of the largest (or smallest if
    False) representable value of the datatype the ordering of these values
    and the masked values is undefined.  To enforce the masked values are
    at the end (beginning) in this case one must sort the mask.
fill_value : {var}, optional
    Value used internally for the masked values.
    If ``fill_value`` is not None, it supersedes ``endwith``.

Returns
-------
sorted_array : ndarray
    Array of the same type and shape as `a`.

See Also
--------
ndarray.sort : Method to sort an array in-place.
argsort : Indirect sort.
lexsort : Indirect stable sort on multiple keys.
searchsorted : Find elements in a sorted array.

Notes
-----
See ``sort`` for notes on the different sorting algorithms.

Examples
--------
>>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Default
>>> a.sort()
>>> print a
[1 3 5 -- --]

>>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Put missing values in the front
>>> a.sort(endwith=False)
>>> print a
[-- -- 1 3 5]

>>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # fill_value takes over endwith
>>> a.sort(endwith=False, fill_value=3)
>>> print a
[1 -- -- 3 5]


def min(self, axis=None, out=None, fill_value=None):

_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>newmask = _check_mask_axis(_mask, axis)<EOL>if fill_value is None:<EOL><INDENT>fill_value = minimum_fill_value(self)<EOL><DEDENT>if out is None:<EOL><INDENT>result = self.filled(fill_value).min(axis=axis, out=out).view(type(self))<EOL>if result.ndim:<EOL><INDENT>result.__setmask__(newmask)<EOL>if newmask.ndim:<EOL><INDENT>np.copyto(result, result.fill_value, where=newmask)<EOL><DEDENT><DEDENT>elif newmask:<EOL><INDENT>result = masked<EOL><DEDENT>return result<EOL><DEDENT>result = self.filled(fill_value).min(axis=axis, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>outmask = getattr(out, '<STR_LIT>', nomask)<EOL>if (outmask is nomask):<EOL><INDENT>outmask = out._mask = make_mask_none(out.shape)<EOL><DEDENT>outmask.flat = newmask<EOL><DEDENT>else:<EOL><INDENT>if out.dtype.kind in '<STR_LIT>':<EOL><INDENT>errmsg = "<STR_LIT>""<STR_LIT>"<EOL>raise MaskError(errmsg)<EOL><DEDENT>np.copyto(out, np.nan, where=newmask)<EOL><DEDENT>return out<EOL>

Return the minimum along a given axis.

Parameters
----------
axis : {None, int}, optional
    Axis along which to operate.  By default, ``axis`` is None and the
    flattened input is used.
out : array_like, optional
    Alternative output array in which to place the result.  Must be of
    the same shape and buffer length as the expected output.
fill_value : {var}, optional
    Value used to fill in the masked values.
    If None, use the output of `minimum_fill_value`.

Returns
-------
amin : array_like
    New array holding the result.
    If ``out`` was specified, ``out`` is returned.

See Also
--------
minimum_fill_value
    Returns the minimum filling value for a given datatype.


if axis is None:<EOL><INDENT>return minimum(self)<EOL><DEDENT>else:<EOL><INDENT>return minimum.reduce(self, axis)<EOL><DEDENT>

Return the array minimum along the specified axis.

Parameters
----------
axis : int, optional
    The axis along which to find the minima. Default is None, in which case
    the minimum value in the whole array is returned.

Returns
-------
min : scalar or MaskedArray
    If `axis` is None, the result is a scalar. Otherwise, if `axis` is
    given and the array is at least 2-D, the result is a masked array with
    dimension one smaller than the array on which `mini` is called.

Examples
--------
>>> x = np.ma.array(np.arange(6), mask=[0 ,1, 0, 0, 0 ,1]).reshape(3, 2)
>>> print x
[[0 --]
 [2 3]
 [4 --]]
>>> x.mini()
0
>>> x.mini(axis=0)
masked_array(data = [0 3],
             mask = [False False],
       fill_value = 999999)
>>> print x.mini(axis=1)
[0 2 4]


def max(self, axis=None, out=None, fill_value=None):

_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>newmask = _check_mask_axis(_mask, axis)<EOL>if fill_value is None:<EOL><INDENT>fill_value = maximum_fill_value(self)<EOL><DEDENT>if out is None:<EOL><INDENT>result = self.filled(fill_value).max(axis=axis, out=out).view(type(self))<EOL>if result.ndim:<EOL><INDENT>result.__setmask__(newmask)<EOL>if newmask.ndim:<EOL><INDENT>np.copyto(result, result.fill_value, where=newmask)<EOL><DEDENT><DEDENT>elif newmask:<EOL><INDENT>result = masked<EOL><DEDENT>return result<EOL><DEDENT>result = self.filled(fill_value).max(axis=axis, out=out)<EOL>if isinstance(out, MaskedArray):<EOL><INDENT>outmask = getattr(out, '<STR_LIT>', nomask)<EOL>if (outmask is nomask):<EOL><INDENT>outmask = out._mask = make_mask_none(out.shape)<EOL><DEDENT>outmask.flat = newmask<EOL><DEDENT>else:<EOL><INDENT>if out.dtype.kind in '<STR_LIT>':<EOL><INDENT>errmsg = "<STR_LIT>""<STR_LIT>"<EOL>raise MaskError(errmsg)<EOL><DEDENT>np.copyto(out, np.nan, where=newmask)<EOL><DEDENT>return out<EOL>

Return the maximum along a given axis.

Parameters
----------
axis : {None, int}, optional
    Axis along which to operate.  By default, ``axis`` is None and the
    flattened input is used.
out : array_like, optional
    Alternative output array in which to place the result.  Must
    be of the same shape and buffer length as the expected output.
fill_value : {var}, optional
    Value used to fill in the masked values.
    If None, use the output of maximum_fill_value().

Returns
-------
amax : array_like
    New array holding the result.
    If ``out`` was specified, ``out`` is returned.

See Also
--------
maximum_fill_value
    Returns the maximum filling value for a given datatype.


def ptp(self, axis=None, out=None, fill_value=None):

if out is None:<EOL><INDENT>result = self.max(axis=axis, fill_value=fill_value)<EOL>result -= self.min(axis=axis, fill_value=fill_value)<EOL>return result<EOL><DEDENT>out.flat = self.max(axis=axis, out=out, fill_value=fill_value)<EOL>min_value = self.min(axis=axis, fill_value=fill_value)<EOL>np.subtract(out, min_value, out=out, casting='<STR_LIT>')<EOL>return out<EOL>

Return (maximum - minimum) along the the given dimension
(i.e. peak-to-peak value).

Parameters
----------
axis : {None, int}, optional
    Axis along which to find the peaks.  If None (default) the
    flattened array is used.
out : {None, array_like}, optional
    Alternative output array in which to place the result. It must
    have the same shape and buffer length as the expected output
    but the type will be cast if necessary.
fill_value : {var}, optional
    Value used to fill in the masked values.

Returns
-------
ptp : ndarray.
    A new array holding the result, unless ``out`` was
    specified, in which case a reference to ``out`` is returned.


_mask = self._mask<EOL>if _mask is nomask:<EOL><INDENT>return self._data.tolist()<EOL><DEDENT>if fill_value is not None:<EOL><INDENT>return self.filled(fill_value).tolist()<EOL><DEDENT>names = self.dtype.names<EOL>if names:<EOL><INDENT>result = self._data.astype([(_, object) for _ in names])<EOL>for n in names:<EOL><INDENT>result[n][_mask[n]] = None<EOL><DEDENT>return result.tolist()<EOL><DEDENT>if _mask is nomask:<EOL><INDENT>return [None]<EOL><DEDENT>inishape = self.shape<EOL>result = np.array(self._data.ravel(), dtype=object)<EOL>result[_mask.ravel()] = None<EOL>result.shape = inishape<EOL>return result.tolist()<EOL>

Return the data portion of the masked array as a hierarchical Python list.

Data items are converted to the nearest compatible Python type.
Masked values are converted to `fill_value`. If `fill_value` is None,
the corresponding entries in the output list will be ``None``.

Parameters
----------
fill_value : scalar, optional
    The value to use for invalid entries. Default is None.

Returns
-------
result : list
    The Python list representation of the masked array.

Examples
--------
>>> x = np.ma.array([[1,2,3], [4,5,6], [7,8,9]], mask=[0] + [1,0]*4)
>>> x.tolist()
[[1, None, 3], [None, 5, None], [7, None, 9]]
>>> x.tolist(-999)
[[1, -999, 3], [-999, 5, -999], [7, -999, 9]]


def tostring(self, fill_value=None, order='<STR_LIT:C>'):

return self.tobytes(fill_value, order='<STR_LIT:C>')<EOL>

This function is a compatibility alias for tobytes. Despite its name it
returns bytes not strings.


def tobytes(self, fill_value=None, order='<STR_LIT:C>'):

return self.filled(fill_value).tobytes(order=order)<EOL>

Return the array data as a string containing the raw bytes in the array.

The array is filled with a fill value before the string conversion.

.. versionadded:: 1.9.0

Parameters
----------
fill_value : scalar, optional
    Value used to fill in the masked values. Deafult is None, in which
    case `MaskedArray.fill_value` is used.
order : {'C','F','A'}, optional
    Order of the data item in the copy. Default is 'C'.

    - 'C'   -- C order (row major).
    - 'F'   -- Fortran order (column major).
    - 'A'   -- Any, current order of array.
    - None  -- Same as 'A'.

See Also
--------
ndarray.tobytes
tolist, tofile

Notes
-----
As for `ndarray.tobytes`, information about the shape, dtype, etc.,
but also about `fill_value`, will be lost.

Examples
--------
>>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.tobytes()
'\\x01\\x00\\x00\\x00?B\\x0f\\x00?B\\x0f\\x00\\x04\\x00\\x00\\x00'


def tofile(self, fid, sep="<STR_LIT>", format="<STR_LIT:%s>"):

raise NotImplementedError("<STR_LIT>")<EOL>

Save a masked array to a file in binary format.

.. warning::
  This function is not implemented yet.

Raises
------
NotImplementedError
    When `tofile` is called.


<EOL>ddtype = self.dtype<EOL>_mask = self._mask<EOL>if _mask is None:<EOL><INDENT>_mask = make_mask_none(self.shape, ddtype)<EOL><DEDENT>mdtype = self._mask.dtype<EOL>record = np.ndarray(shape=self.shape,<EOL>dtype=[('<STR_LIT>', ddtype), ('<STR_LIT>', mdtype)])<EOL>record['<STR_LIT>'] = self._data<EOL>record['<STR_LIT>'] = self._mask<EOL>return record<EOL>

Transforms a masked array into a flexible-type array.

The flexible type array that is returned will have two fields:

* the ``_data`` field stores the ``_data`` part of the array.
* the ``_mask`` field stores the ``_mask`` part of the array.

Parameters
----------
None

Returns
-------
record : ndarray
    A new flexible-type `ndarray` with two fields: the first element
    containing a value, the second element containing the corresponding
    mask boolean. The returned record shape matches self.shape.

Notes
-----
A side-effect of transforming a masked array into a flexible `ndarray` is
that meta information (``fill_value``, ...) will be lost.

Examples
--------
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> print x
[[1 -- 3]
 [-- 5 --]
 [7 -- 9]]
>>> print x.toflex()
[[(1, False) (2, True) (3, False)]
 [(4, True) (5, False) (6, True)]
 [(7, False) (8, True) (9, False)]]


cf = '<STR_LIT>'[self.flags.fnc]<EOL>state = (<NUM_LIT:1>,<EOL>self.shape,<EOL>self.dtype,<EOL>self.flags.fnc,<EOL>self._data.tobytes(cf),<EOL>getmaskarray(self).tobytes(cf),<EOL>self._fill_value,<EOL>)<EOL>return state<EOL>

Return the internal state of the masked array, for pickling
        purposes.


(_, shp, typ, isf, raw, msk, flv) = state<EOL>ndarray.__setstate__(self, (shp, typ, isf, raw))<EOL>self._mask.__setstate__((shp, make_mask_descr(typ), isf, msk))<EOL>self.fill_value = flv<EOL>

Restore the internal state of the masked array, for
        pickling purposes.  ``state`` is typically the output of the
        ``__getstate__`` output, and is a 5-tuple:

        - class name
        - a tuple giving the shape of the data
        - a typecode for the data
        - a binary string for the data
        - a binary string for the mask.


return (_mareconstruct,<EOL>(self.__class__, self._baseclass, (<NUM_LIT:0>,), '<STR_LIT:b>',),<EOL>self.__getstate__())<EOL>

Return a 3-tuple for pickling a MaskedArray.


m = self._mask<EOL>if m is not nomask and m[indx]:<EOL><INDENT>return masked<EOL><DEDENT>return self._data[indx]<EOL>


(_data, _mask) = (self._data, self._mask)<EOL>if _mask is nomask:<EOL><INDENT>for d in _data:<EOL><INDENT>yield d<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for (d, m) in zip(_data, _mask):<EOL><INDENT>if m:<EOL><INDENT>yield masked<EOL><DEDENT>else:<EOL><INDENT>yield d<EOL><DEDENT><DEDENT><DEDENT>


return asarray(self).filled(fill_value)[()]<EOL>

Return a copy with masked fields filled with a given value.

Parameters
----------
fill_value : scalar, optional
    The value to use for invalid entries (None by default).
    If None, the `fill_value` attribute is used instead.

Returns
-------
filled_void
    A `np.void` object

See Also
--------
MaskedArray.filled


_mask = self._mask<EOL>if _mask is nomask:<EOL><INDENT>return self._data.tolist()<EOL><DEDENT>result = []<EOL>for (d, m) in zip(self._data, self._mask):<EOL><INDENT>if m:<EOL><INDENT>result.append(None)<EOL><DEDENT>else:<EOL><INDENT>result.append(d.item())<EOL><DEDENT><DEDENT>return tuple(result)<EOL>

Transforms the mvoid object into a tuple.

Masked fields are replaced by None.

Returns
-------
returned_tuple
    Tuple of fields


return (self.__class__, ())<EOL>


if b is None:<EOL><INDENT>return self.reduce(a)<EOL><DEDENT>return where(self.compare(a, b), a, b)<EOL>


target = narray(target, copy=False, subok=True)<EOL>m = getmask(target)<EOL>if axis is not None:<EOL><INDENT>kargs = { '<STR_LIT>' : axis }<EOL><DEDENT>else:<EOL><INDENT>kargs = {}<EOL>target = target.ravel()<EOL>if not (m is nomask):<EOL><INDENT>m = m.ravel()<EOL><DEDENT><DEDENT>if m is nomask:<EOL><INDENT>t = self.ufunc.reduce(target, **kargs)<EOL><DEDENT>else:<EOL><INDENT>target = target.filled(self.fill_value_func(target)).view(type(target))<EOL>t = self.ufunc.reduce(target, **kargs)<EOL>m = umath.logical_and.reduce(m, **kargs)<EOL>if hasattr(t, '<STR_LIT>'):<EOL><INDENT>t._mask = m<EOL><DEDENT>elif m:<EOL><INDENT>t = masked<EOL><DEDENT><DEDENT>return t<EOL>


ma = getmask(a)<EOL>mb = getmask(b)<EOL>if ma is nomask and mb is nomask:<EOL><INDENT>m = nomask<EOL><DEDENT>else:<EOL><INDENT>ma = getmaskarray(a)<EOL>mb = getmaskarray(b)<EOL>m = logical_or.outer(ma, mb)<EOL><DEDENT>result = self.ufunc.outer(filled(a), filled(b))<EOL>if not isinstance(result, MaskedArray):<EOL><INDENT>result = result.view(MaskedArray)<EOL><DEDENT>result._mask = m<EOL>return result<EOL>

Return the function applied to the outer product of a and b.


self.ufunc = umath.minimum<EOL>self.afunc = amin<EOL>self.compare = less<EOL>self.fill_value_func = minimum_fill_value<EOL>

minimum(a, b) or minimum(a)
In one argument case, returns the scalar minimum.


self.ufunc = umath.maximum<EOL>self.afunc = amax<EOL>self.compare = greater<EOL>self.fill_value_func = maximum_fill_value<EOL>

maximum(a, b) or maximum(a)
           In one argument case returns the scalar maximum.


meth = getattr(MaskedArray, self.__name__, None) orgetattr(np, self.__name__, None)<EOL>signature = self.__name__ + get_object_signature(meth)<EOL>if meth is not None:<EOL><INDENT>doc = """<STR_LIT>""" % (signature, getattr(meth, '<STR_LIT>', None))<EOL>return doc<EOL><DEDENT>

Return the doc of the function (from the doc of the method).


doc = getattr(self._func, '<STR_LIT>', None)<EOL>sig = get_object_signature(self._func)<EOL>if doc:<EOL><INDENT>if sig:<EOL><INDENT>sig = "<STR_LIT>" % (self._func.__name__, sig)<EOL><DEDENT>doc = sig + doc<EOL><DEDENT>return doc<EOL>


def approx (a, b, fill_value=True, rtol=<NUM_LIT>, atol=<NUM_LIT>):

m = mask_or(getmask(a), getmask(b))<EOL>d1 = filled(a)<EOL>d2 = filled(b)<EOL>if d1.dtype.char == "<STR_LIT:O>" or d2.dtype.char == "<STR_LIT:O>":<EOL><INDENT>return np.equal(d1, d2).ravel()<EOL><DEDENT>x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)<EOL>y = filled(masked_array(d2, copy=False, mask=m), <NUM_LIT:1>).astype(float_)<EOL>d = np.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y))<EOL>return d.ravel()<EOL>

Returns true if all components of a and b are equal subject to given tolerances.

If fill_value is True, masked values considered equal. Otherwise, masked values
are considered unequal.
The relative error rtol should be positive and << 1.0
The absolute error atol comes into play for those elements of b that are very
small or zero; it says how small a must be also.


def almost(a, b, decimal=<NUM_LIT:6>, fill_value=True):

m = mask_or(getmask(a), getmask(b))<EOL>d1 = filled(a)<EOL>d2 = filled(b)<EOL>if d1.dtype.char == "<STR_LIT:O>" or d2.dtype.char == "<STR_LIT:O>":<EOL><INDENT>return np.equal(d1, d2).ravel()<EOL><DEDENT>x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)<EOL>y = filled(masked_array(d2, copy=False, mask=m), <NUM_LIT:1>).astype(float_)<EOL>d = np.around(np.abs(x - y), decimal) <= <NUM_LIT> ** (-decimal)<EOL>return d.ravel()<EOL>

Returns True if a and b are equal up to decimal places.
If fill_value is True, masked values considered equal. Otherwise, masked values
are considered unequal.


def _assert_equal_on_sequences(actual, desired, err_msg='<STR_LIT>'):

assert_equal(len(actual), len(desired), err_msg)<EOL>for k in range(len(desired)):<EOL><INDENT>assert_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg))<EOL><DEDENT>return<EOL>

Asserts the equality of two non-array sequences.


assert_equal(a.dtype, b.dtype)<EOL>for f in a.dtype.names:<EOL><INDENT>(af, bf) = (operator.getitem(a, f), operator.getitem(b, f))<EOL>if not (af is masked) and not (bf is masked):<EOL><INDENT>assert_equal(operator.getitem(a, f), operator.getitem(b, f))<EOL><DEDENT><DEDENT>return<EOL>

Asserts that two records are equal. Pretty crude for now.


def assert_equal(actual, desired, err_msg='<STR_LIT>'):

<EOL>if isinstance(desired, dict):<EOL><INDENT>if not isinstance(actual, dict):<EOL><INDENT>raise AssertionError(repr(type(actual)))<EOL><DEDENT>assert_equal(len(actual), len(desired), err_msg)<EOL>for k, i in desired.items():<EOL><INDENT>if not k in actual:<EOL><INDENT>raise AssertionError("<STR_LIT>" % (k, actual))<EOL><DEDENT>assert_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg))<EOL><DEDENT>return<EOL><DEDENT>if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):<EOL><INDENT>return _assert_equal_on_sequences(actual, desired, err_msg='<STR_LIT>')<EOL><DEDENT>if not (isinstance(actual, ndarray) or isinstance(desired, ndarray)):<EOL><INDENT>msg = build_err_msg([actual, desired], err_msg,)<EOL>if not desired == actual:<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT>return<EOL><DEDENT>if ((actual is masked) and not (desired is masked)) or((desired is masked) and not (actual is masked)):<EOL><INDENT>msg = build_err_msg([actual, desired],<EOL>err_msg, header='<STR_LIT>', names=('<STR_LIT:x>', '<STR_LIT:y>'))<EOL>raise ValueError(msg)<EOL><DEDENT>actual = np.array(actual, copy=False, subok=True)<EOL>desired = np.array(desired, copy=False, subok=True)<EOL>(actual_dtype, desired_dtype) = (actual.dtype, desired.dtype)<EOL>if actual_dtype.char == "<STR_LIT:S>" and desired_dtype.char == "<STR_LIT:S>":<EOL><INDENT>return _assert_equal_on_sequences(actual.tolist(),<EOL>desired.tolist(),<EOL>err_msg='<STR_LIT>')<EOL>


def fail_if_equal(actual, desired, err_msg='<STR_LIT>',):

if isinstance(desired, dict):<EOL><INDENT>if not isinstance(actual, dict):<EOL><INDENT>raise AssertionError(repr(type(actual)))<EOL><DEDENT>fail_if_equal(len(actual), len(desired), err_msg)<EOL>for k, i in desired.items():<EOL><INDENT>if not k in actual:<EOL><INDENT>raise AssertionError(repr(k))<EOL><DEDENT>fail_if_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg))<EOL><DEDENT>return<EOL><DEDENT>if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):<EOL><INDENT>fail_if_equal(len(actual), len(desired), err_msg)<EOL>for k in range(len(desired)):<EOL><INDENT>fail_if_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg))<EOL><DEDENT>return<EOL><DEDENT>if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):<EOL><INDENT>return fail_if_array_equal(actual, desired, err_msg)<EOL><DEDENT>msg = build_err_msg([actual, desired], err_msg)<EOL>if not desired != actual:<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT>

Raises an assertion error if two items are equal.


def assert_almost_equal(actual, desired, decimal=<NUM_LIT:7>, err_msg='<STR_LIT>', verbose=True):

if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):<EOL><INDENT>return assert_array_almost_equal(actual, desired, decimal=decimal,<EOL>err_msg=err_msg, verbose=verbose)<EOL><DEDENT>msg = build_err_msg([actual, desired],<EOL>err_msg=err_msg, verbose=verbose)<EOL>if not round(abs(desired - actual), decimal) == <NUM_LIT:0>:<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT>

Asserts that two items are almost equal.
    The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal)


def assert_array_compare(comparison, x, y, err_msg='<STR_LIT>', verbose=True, header='<STR_LIT>',<EOL>fill_value=True):

<EOL><INDENT>xf = filled(x)<EOL>yf = filled(y)<EOL><DEDENT>m = mask_or(getmask(x), getmask(y))<EOL>x = masked_array(x, copy=False, mask=m, keep_mask=False, subok=False)<EOL>y = masked_array(y, copy=False, mask=m, keep_mask=False, subok=False)<EOL>if ((x is masked) and not (y is masked)) or((y is masked) and not (x is masked)):<EOL><INDENT>msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose,<EOL>header=header, names=('<STR_LIT:x>', '<STR_LIT:y>'))<EOL>raise ValueError(msg)<EOL><DEDENT>return utils.assert_array_compare(comparison,<EOL>x.filled(fill_value),<EOL>y.filled(fill_value),<EOL>err_msg=err_msg,<EOL>verbose=verbose, header=header)<EOL>

Asserts that a comparison relation between two masked arrays is satisfied
    elementwise.


def assert_array_equal(x, y, err_msg='<STR_LIT>', verbose=True):

assert_array_compare(operator.__eq__, x, y,<EOL>err_msg=err_msg, verbose=verbose,<EOL>header='<STR_LIT>')<EOL>

Checks the elementwise equality of two masked arrays.


def fail_if_array_equal(x, y, err_msg='<STR_LIT>', verbose=True):

def compare(x, y):<EOL><INDENT>return (not np.alltrue(approx(x, y)))<EOL><DEDENT>assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,<EOL>header='<STR_LIT>')<EOL>

Raises an assertion error if two masked arrays are not equal (elementwise).


def assert_array_approx_equal(x, y, decimal=<NUM_LIT:6>, err_msg='<STR_LIT>', verbose=True):

def compare(x, y):<EOL><INDENT>"<STR_LIT>"<EOL>return approx(x, y, rtol=<NUM_LIT> ** -decimal)<EOL><DEDENT>assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,<EOL>header='<STR_LIT>')<EOL>

Checks the elementwise equality of two masked arrays, up to a given
    number of decimals.


def assert_array_almost_equal(x, y, decimal=<NUM_LIT:6>, err_msg='<STR_LIT>', verbose=True):

def compare(x, y):<EOL><INDENT>"<STR_LIT>"<EOL>return almost(x, y, decimal)<EOL><DEDENT>assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,<EOL>header='<STR_LIT>')<EOL>


def assert_array_less(x, y, err_msg='<STR_LIT>', verbose=True):

assert_array_compare(operator.__lt__, x, y,<EOL>err_msg=err_msg, verbose=verbose,<EOL>header='<STR_LIT>')<EOL>

Checks that x is smaller than y elementwise.


def assert_mask_equal(m1, m2, err_msg='<STR_LIT>'):

if m1 is nomask:<EOL><INDENT>assert_(m2 is nomask)<EOL><DEDENT>if m2 is nomask:<EOL><INDENT>assert_(m1 is nomask)<EOL><DEDENT>assert_array_equal(m1, m2, err_msg=err_msg)<EOL>


def assert_array_compare(self, comparison, x, y, err_msg='<STR_LIT>', header='<STR_LIT>',<EOL>fill_value=True):

xf = self.filled(x)<EOL>yf = self.filled(y)<EOL>m = self.mask_or(self.getmask(x), self.getmask(y))<EOL>x = self.filled(self.masked_array(xf, mask=m), fill_value)<EOL>y = self.filled(self.masked_array(yf, mask=m), fill_value)<EOL>if (x.dtype.char != "<STR_LIT:O>"):<EOL><INDENT>x = x.astype(float_)<EOL>if isinstance(x, np.ndarray) and x.size > <NUM_LIT:1>:<EOL><INDENT>x[np.isnan(x)] = <NUM_LIT:0><EOL><DEDENT>elif np.isnan(x):<EOL><INDENT>x = <NUM_LIT:0><EOL><DEDENT><DEDENT>if (y.dtype.char != "<STR_LIT:O>"):<EOL><INDENT>y = y.astype(float_)<EOL>if isinstance(y, np.ndarray) and y.size > <NUM_LIT:1>:<EOL><INDENT>y[np.isnan(y)] = <NUM_LIT:0><EOL><DEDENT>elif np.isnan(y):<EOL><INDENT>y = <NUM_LIT:0><EOL><DEDENT><DEDENT>try:<EOL><INDENT>cond = (x.shape==() or y.shape==()) or x.shape == y.shape<EOL>if not cond:<EOL><INDENT>msg = build_err_msg([x, y],<EOL>err_msg<EOL>+ '<STR_LIT>' % (x.shape,<EOL>y.shape),<EOL>header=header,<EOL>names=('<STR_LIT:x>', '<STR_LIT:y>'))<EOL>assert cond, msg<EOL><DEDENT>val = comparison(x, y)<EOL>if m is not self.nomask and fill_value:<EOL><INDENT>val = self.masked_array(val, mask=m)<EOL><DEDENT>if isinstance(val, bool):<EOL><INDENT>cond = val<EOL>reduced = [<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>reduced = val.ravel()<EOL>cond = reduced.all()<EOL>reduced = reduced.tolist()<EOL><DEDENT>if not cond:<EOL><INDENT>match = <NUM_LIT:100>-<NUM_LIT>*reduced.count(<NUM_LIT:1>)/len(reduced)<EOL>msg = build_err_msg([x, y],<EOL>err_msg<EOL>+ '<STR_LIT>' % (match,),<EOL>header=header,<EOL>names=('<STR_LIT:x>', '<STR_LIT:y>'))<EOL>assert cond, msg<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>msg = build_err_msg([x, y], err_msg, header=header, names=('<STR_LIT:x>', '<STR_LIT:y>'))<EOL>raise ValueError(msg)<EOL><DEDENT>

Asserts that a comparison relation between two masked arrays is satisfied
        elementwise.


def assert_array_equal(self, x, y, err_msg='<STR_LIT>'):

self.assert_array_compare(self.equal, x, y, err_msg=err_msg,<EOL>header='<STR_LIT>')<EOL>


>>> 2+2
<BadExample object at 0x084D05AC>  #random: may vary on your system


# whitespace after the 3
>>> 1+2
3

# whitespace before the 7
>>> 3+4
 7


Check that no output does not cause an error.

    This is related to nose bug 445; the numpy plugin changed the
    doctest-result-variable default and therefore hit this bug:
    http://code.google.com/p/python-nose/issues/detail?id=445

    >>> a = 10


Check skip directive

    The test below should not run

    >>> 1/0 #doctest: +SKIP


fullpath = filepath[:]<EOL>pkg_name = []<EOL>while '<STR_LIT>' in filepath or '<STR_LIT>' in filepath:<EOL><INDENT>filepath, p2 = os.path.split(filepath)<EOL>if p2 in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>pkg_name.append(p2)<EOL><DEDENT>if not pkg_name:<EOL><INDENT>if '<STR_LIT>' in fullpath:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>pkg_name.reverse()<EOL>if pkg_name[<NUM_LIT:0>].endswith('<STR_LIT>'):<EOL><INDENT>pkg_name.pop(<NUM_LIT:0>)<EOL><DEDENT>return '<STR_LIT:.>'.join(pkg_name)<EOL>

Given a path where a package is installed, determine its name.

Parameters
----------
filepath : str
    Path to a file. If the determination fails, "numpy" is returned.

Examples
--------
>>> np.testing.nosetester.get_package_name('nonsense')
'numpy'


fine_nose = True<EOL>minimum_nose_version = (<NUM_LIT:0>, <NUM_LIT:10>, <NUM_LIT:0>)<EOL>try:<EOL><INDENT>import nose<EOL><DEDENT>except ImportError:<EOL><INDENT>fine_nose = False<EOL><DEDENT>else:<EOL><INDENT>if nose.__versioninfo__ < minimum_nose_version:<EOL><INDENT>fine_nose = False<EOL><DEDENT><DEDENT>if not fine_nose:<EOL><INDENT>msg = '<STR_LIT>''<STR_LIT>' %minimum_nose_version<EOL>raise ImportError(msg)<EOL><DEDENT>return nose<EOL>


if file_to_run is None:<EOL><INDENT>f = sys._getframe(<NUM_LIT:1>)<EOL>file_to_run = f.f_locals.get('<STR_LIT>', None)<EOL>if file_to_run is None:<EOL><INDENT>raise AssertionError<EOL><DEDENT><DEDENT>if argv is None:<EOL><INDENT>argv = ['<STR_LIT>', file_to_run]<EOL><DEDENT>else:<EOL><INDENT>argv = argv + [file_to_run]<EOL><DEDENT>nose = import_nose()<EOL>from .noseclasses import KnownFailure<EOL>nose.run(argv=argv, addplugins=[KnownFailure()])<EOL>

Run a test module.

Equivalent to calling ``$ nosetests <argv> <file_to_run>`` from
the command line

Parameters
----------
file_to_run: str, optional
    Path to test module, or None.
    By default, run the module from which this function is called.
argv: list of strings
    Arguments to be passed to the nose test runner. ``argv[0]`` is
    ignored. All command line arguments accepted by ``nosetests``
    will work.

    .. versionadded:: 1.9.0

Examples
--------
Adding the following::

    if __name__ == "__main__" :
        run_module_suite(argv=sys.argv)

at the end of a test module will run the tests when that module is
called in the python interpreter.

Alternatively, calling::

>>> run_module_suite(file_to_run="numpy/tests/test_matlib.py")

from an interpreter will run all the test routine in 'test_matlib.py'.


def bench(self, label='<STR_LIT>', verbose=<NUM_LIT:1>, extra_argv=None):

print("<STR_LIT>" % self.package_name)<EOL>self._show_system_info()<EOL>argv = self._test_argv(label, verbose, extra_argv)<EOL>argv += ['<STR_LIT>', r'<STR_LIT>' % os.sep]<EOL>nose = import_nose()<EOL>from .noseclasses import Unplugger<EOL>add_plugins = [Unplugger('<STR_LIT>')]<EOL>return nose.run(argv=argv, addplugins=add_plugins)<EOL>

Run benchmarks for module using nose.

Parameters
----------
label : {'fast', 'full', '', attribute identifier}, optional
    Identifies the benchmarks to run. This can be a string to pass to
    the nosetests executable with the '-A' option, or one of several
    special values.  Special values are:
    * 'fast' - the default - which corresponds to the ``nosetests -A``
      option of 'not slow'.
    * 'full' - fast (as above) and slow benchmarks as in the
      'no -A' option to nosetests - this is the same as ''.
    * None or '' - run all tests.
    attribute_identifier - string passed directly to nosetests as '-A'.
verbose : int, optional
    Verbosity value for benchmark outputs, in the range 1-10. Default is 1.
extra_argv : list, optional
    List with any extra arguments to pass to nosetests.

Returns
-------
success : bool
    Returns True if running the benchmarks works, False if an error
    occurred.

Notes
-----
Benchmarks are like tests, but have names starting with "bench" instead
of "test", and can be found under the "benchmarks" sub-directory of the
module.

Each NumPy module exposes `bench` in its namespace to run all benchmarks
for it.

Examples
--------
>>> success = np.lib.bench() #doctest: +SKIP
Running benchmarks for numpy.lib
...
using 562341 items:
unique:
0.11
unique1d:
0.11
ratio: 1.0
nUnique: 56230 == 56230
...
OK

>>> success #doctest: +SKIP
True


if module is None:<EOL><INDENT>return True<EOL><DEDENT>elif inspect.isfunction(object):<EOL><INDENT>return module.__dict__ is object.__globals__<EOL><DEDENT>elif inspect.isbuiltin(object):<EOL><INDENT>return module.__name__ == object.__module__<EOL><DEDENT>elif inspect.isclass(object):<EOL><INDENT>return module.__name__ == object.__module__<EOL><DEDENT>elif inspect.ismethod(object):<EOL><INDENT>return module.__name__ == object.__self__.__class__.__module__<EOL><DEDENT>elif inspect.getmodule(object) is not None:<EOL><INDENT>return module is inspect.getmodule(object)<EOL><DEDENT>elif hasattr(object, '<STR_LIT>'):<EOL><INDENT>return module.__name__ == object.__module__<EOL><DEDENT>elif isinstance(object, property):<EOL><INDENT>return True <EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>

Return true if the given object is defined in the given
module.


if self.testRunner is None:<EOL><INDENT>self.testRunner = nose.core.TextTestRunner(stream=self.config.stream,<EOL>verbosity=self.config.verbosity,<EOL>config=self.config)<EOL><DEDENT>plug_runner = self.config.plugins.prepareTestRunner(self.testRunner)<EOL>if plug_runner is not None:<EOL><INDENT>self.testRunner = plug_runner<EOL><DEDENT>self.result = self.testRunner.run(self.test)<EOL>self.success = self.result.wasSuccessful()<EOL>return self.success<EOL>

Run Tests. Returns true on success, false on failure, and
        sets self.success to the same value.

        Because nose currently discards the test result object, but we need
        to return it to the user, override TestProgram.runTests to retain
        the result


if not val :<EOL><INDENT>try:<EOL><INDENT>smsg = msg()<EOL><DEDENT>except TypeError:<EOL><INDENT>smsg = msg<EOL><DEDENT>raise AssertionError(smsg)<EOL><DEDENT>

Assert that works in release mode.
Accepts callable msg to allow deferring evaluation until failure.

The Python built-in ``assert`` does not work when executing code in
optimized mode (the ``-O`` flag) - no byte-code is generated for it.

For documentation on usage, refer to the Python documentation.


from numpy.core import isnan<EOL>st = isnan(x)<EOL>if isinstance(st, type(NotImplemented)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>return st<EOL>

like isnan, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isnan and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.


from numpy.core import isfinite, errstate<EOL>with errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>st = isfinite(x)<EOL>if isinstance(st, type(NotImplemented)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>return st<EOL>

like isfinite, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isfinite and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.


from numpy.core import isinf, errstate<EOL>with errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>st = isinf(x)<EOL>if isinstance(st, type(NotImplemented)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>return st<EOL>

like isinf, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isinf and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.


import random<EOL>from numpy.core import zeros, float64<EOL>results = zeros(args, float64)<EOL>f = results.flat<EOL>for i in range(len(f)):<EOL><INDENT>f[i] = random.random()<EOL><DEDENT>return results<EOL>

Returns an array of random numbers with the given shape.

    This only uses the standard library, so it is useful for testing purposes.


if isinstance(desired, dict):<EOL><INDENT>if not isinstance(actual, dict) :<EOL><INDENT>raise AssertionError(repr(type(actual)))<EOL><DEDENT>assert_equal(len(actual), len(desired), err_msg, verbose)<EOL>for k, i in desired.items():<EOL><INDENT>if k not in actual :<EOL><INDENT>raise AssertionError(repr(k))<EOL><DEDENT>assert_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg), verbose)<EOL><DEDENT>return<EOL><DEDENT>if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):<EOL><INDENT>assert_equal(len(actual), len(desired), err_msg, verbose)<EOL>for k in range(len(desired)):<EOL><INDENT>assert_equal(actual[k], desired[k], '<STR_LIT>' % (k, err_msg), verbose)<EOL><DEDENT>return<EOL><DEDENT>from numpy.core import ndarray, isscalar, signbit<EOL>from numpy.lib import iscomplexobj, real, imag<EOL>if isinstance(actual, ndarray) or isinstance(desired, ndarray):<EOL><INDENT>return assert_array_equal(actual, desired, err_msg, verbose)<EOL><DEDENT>msg = build_err_msg([actual, desired], err_msg, verbose=verbose)<EOL>try:<EOL><INDENT>usecomplex = iscomplexobj(actual) or iscomplexobj(desired)<EOL><DEDENT>except ValueError:<EOL><INDENT>usecomplex = False<EOL><DEDENT>if usecomplex:<EOL><INDENT>if iscomplexobj(actual):<EOL><INDENT>actualr = real(actual)<EOL>actuali = imag(actual)<EOL><DEDENT>else:<EOL><INDENT>actualr = actual<EOL>actuali = <NUM_LIT:0><EOL><DEDENT>if iscomplexobj(desired):<EOL><INDENT>desiredr = real(desired)<EOL>desiredi = imag(desired)<EOL><DEDENT>else:<EOL><INDENT>desiredr = desired<EOL>desiredi = <NUM_LIT:0><EOL><DEDENT>try:<EOL><INDENT>assert_equal(actualr, desiredr)<EOL>assert_equal(actuali, desiredi)<EOL><DEDENT>except AssertionError:<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>if isscalar(desired) != isscalar(actual):<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT>if not (gisfinite(desired) and gisfinite(actual)):<EOL><INDENT>isdesnan = gisnan(desired)<EOL>isactnan = gisnan(actual)<EOL>if isdesnan or isactnan:<EOL><INDENT>if not (isdesnan and isactnan):<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not desired == actual:<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT><DEDENT>return<EOL><DEDENT>elif desired == <NUM_LIT:0> and actual == <NUM_LIT:0>:<EOL><INDENT>if not signbit(desired) == signbit(actual):<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT><DEDENT><DEDENT>except (TypeError, ValueError, NotImplementedError):<EOL><INDENT>pass<EOL><DEDENT>if not (desired == actual):<EOL><INDENT>raise AssertionError(msg)<EOL><DEDENT>

Raises an AssertionError if two objects are not equal.

Given two objects (scalars, lists, tuples, dictionaries or numpy arrays),
check that all elements of these objects are equal. An exception is raised
at the first conflicting values.

Parameters
----------
actual : array_like
    The object to check.
desired : array_like
    The expected object.
err_msg : str, optional
    The error message to be printed in case of failure.
verbose : bool, optional
    If True, the conflicting values are appended to the error message.

Raises
------
AssertionError
    If actual and desired are not equal.

Examples
--------
>>> np.testing.assert_equal([4,5], [4,6])
...
<type 'exceptions.AssertionError'>:
Items are not equal:
item=1
 ACTUAL: 5
 DESIRED: 6