ndescr = len(descr)<EOL>default_names = ['<STR_LIT>' % i for i in range(ndescr)]<EOL>if names is None:<EOL><INDENT>new_names = default_names<EOL><DEDENT>else:<EOL><INDENT>if isinstance(names, (tuple, list)):<EOL><INDENT>new_names = names<EOL><DEDENT>elif isinstance(names, str):<EOL><INDENT>new_names = names.split('<STR_LIT:U+002C>')<EOL><DEDENT>else:<EOL><INDENT>raise NameError("<STR_LIT>" % repr(names))<EOL><DEDENT>nnames = len(new_names)<EOL>if nnames < ndescr:<EOL><INDENT>new_names += default_names[nnames:]<EOL><DEDENT><DEDENT>ndescr = []<EOL>for (n, d, t) in zip(new_names, default_names, descr.descr):<EOL><INDENT>if n in reserved_fields:<EOL><INDENT>if t[<NUM_LIT:0>] in reserved_fields:<EOL><INDENT>ndescr.append((d, t[<NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>ndescr.append(t)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ndescr.append((n, t[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>return np.dtype(ndescr)<EOL>

Checks that the field names of the descriptor ``descr`` are not some
reserved keywords. If this is the case, a default 'f%i' is substituted.
If the argument `names` is not None, updates the field names to valid names.


def _mrreconstruct(subtype, baseclass, baseshape, basetype,):

_data = ndarray.__new__(baseclass, baseshape, basetype).view(subtype)<EOL><INDENT>_data._mask = ndarray.__new__(ndarray, baseshape, '<STR_LIT>')<EOL>return _data<EOL><DEDENT>_mask = ndarray.__new__(ndarray, baseshape, '<STR_LIT>')<EOL>return subtype.__new__(subtype, _data, mask=_mask, dtype=basetype,)<EOL>

Internal function that builds a new MaskedArray from the
    information stored in a pickle.


def fromarrays(arraylist, dtype=None, shape=None, formats=None,<EOL>names=None, titles=None, aligned=False, byteorder=None,<EOL>fill_value=None):

datalist = [getdata(x) for x in arraylist]<EOL>masklist = [np.atleast_1d(getmaskarray(x)) for x in arraylist]<EOL>_array = recfromarrays(datalist,<EOL>dtype=dtype, shape=shape, formats=formats,<EOL>names=names, titles=titles, aligned=aligned,<EOL>byteorder=byteorder).view(mrecarray)<EOL>_array._mask.flat = list(zip(*masklist))<EOL>if fill_value is not None:<EOL><INDENT>_array.fill_value = fill_value<EOL><DEDENT>return _array<EOL>

Creates a mrecarray from a (flat) list of masked arrays.

    Parameters
    ----------
    arraylist : sequence
        A list of (masked) arrays. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None, integer}, optional
        Number of records. If None, shape is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.


def fromrecords(reclist, dtype=None, shape=None, formats=None, names=None,<EOL>titles=None, aligned=False, byteorder=None,<EOL>fill_value=None, mask=nomask):

<EOL>_mask = getattr(reclist, '<STR_LIT>', None)<EOL>try:<EOL><INDENT>nfields = len(reclist[<NUM_LIT:0>])<EOL><DEDENT>except TypeError:<EOL><INDENT>nfields = len(reclist[<NUM_LIT:0>].dtype)<EOL><DEDENT>if isinstance(reclist, ndarray):<EOL><INDENT>if isinstance(reclist, MaskedArray):<EOL><INDENT>reclist = reclist.filled().view(ndarray)<EOL><DEDENT>if dtype is None:<EOL><INDENT>dtype = reclist.dtype<EOL><DEDENT>reclist = reclist.tolist()<EOL><DEDENT>mrec = recfromrecords(reclist, dtype=dtype, shape=shape, formats=formats,<EOL>names=names, titles=titles,<EOL>aligned=aligned, byteorder=byteorder).view(mrecarray)<EOL>if fill_value is not None:<EOL><INDENT>mrec.fill_value = fill_value<EOL><DEDENT>if mask is not nomask:<EOL><INDENT>mask = np.array(mask, copy=False)<EOL>maskrecordlength = len(mask.dtype)<EOL>if maskrecordlength:<EOL><INDENT>mrec._mask.flat = mask<EOL><DEDENT>elif len(mask.shape) == <NUM_LIT:2>:<EOL><INDENT>mrec._mask.flat = [tuple(m) for m in mask]<EOL><DEDENT>else:<EOL><INDENT>mrec.__setmask__(mask)<EOL><DEDENT><DEDENT>if _mask is not None:<EOL><INDENT>mrec._mask[:] = _mask<EOL><DEDENT>return mrec<EOL>

Creates a MaskedRecords from a list of records.

    Parameters
    ----------
    reclist : sequence
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None,int}, optional
        Number of records. If None, ``shape`` is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.
    mask : {nomask, sequence}, optional.
        External mask to apply on the data.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.


vartypes = []<EOL>arr = np.asarray(arr)<EOL>if len(arr.shape) == <NUM_LIT:2> :<EOL><INDENT>arr = arr[<NUM_LIT:0>]<EOL><DEDENT>elif len(arr.shape) > <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>for f in arr:<EOL><INDENT>try:<EOL><INDENT>int(f)<EOL><DEDENT>except ValueError:<EOL><INDENT>try:<EOL><INDENT>float(f)<EOL><DEDENT>except ValueError:<EOL><INDENT>try:<EOL><INDENT>val = complex(f)<EOL><DEDENT>except ValueError:<EOL><INDENT>vartypes.append(arr.dtype)<EOL><DEDENT>else:<EOL><INDENT>vartypes.append(np.dtype(complex))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>vartypes.append(np.dtype(float))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>vartypes.append(np.dtype(int))<EOL><DEDENT><DEDENT>return vartypes<EOL>

Tries to guess the dtypes of the str_ ndarray `arr`, by testing element-wise
conversion. Returns a list of dtypes.
The array is first converted to ndarray. If the array is 2D, the test is performed
on the first line. An exception is raised if the file is 3D or more.


<EOL>if hasattr(fname, '<STR_LIT>'):<EOL><INDENT>return fname<EOL><DEDENT>try:<EOL><INDENT>f = open(fname)<EOL><DEDENT>except IOError:<EOL><INDENT>raise IOError("<STR_LIT>" % fname)<EOL><DEDENT>if f.readline()[:<NUM_LIT:2>] != "<STR_LIT>":<EOL><INDENT>f.seek(<NUM_LIT:0>, <NUM_LIT:0>)<EOL>return f<EOL><DEDENT>f.close()<EOL>raise NotImplementedError("<STR_LIT>")<EOL>


def fromtextfile(fname, delimitor=None, commentchar='<STR_LIT:#>', missingchar='<STR_LIT>',<EOL>varnames=None, vartypes=None):

<EOL>f = openfile(fname)<EOL>while True:<EOL><INDENT>line = f.readline()<EOL>firstline = line[:line.find(commentchar)].strip()<EOL>_varnames = firstline.split(delimitor)<EOL>if len(_varnames) > <NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if varnames is None:<EOL><INDENT>varnames = _varnames<EOL><DEDENT>_variables = masked_array([line.strip().split(delimitor) for line in f<EOL>if line[<NUM_LIT:0>] != commentchar and len(line) > <NUM_LIT:1>])<EOL>(_, nfields) = _variables.shape<EOL>f.close()<EOL>if vartypes is None:<EOL><INDENT>vartypes = _guessvartypes(_variables[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>vartypes = [np.dtype(v) for v in vartypes]<EOL>if len(vartypes) != nfields:<EOL><INDENT>msg = "<STR_LIT>"<EOL>msg += "<STR_LIT>"<EOL>warnings.warn(msg % (len(vartypes), nfields))<EOL>vartypes = _guessvartypes(_variables[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>mdescr = [(n, f) for (n, f) in zip(varnames, vartypes)]<EOL>mfillv = [ma.default_fill_value(f) for f in vartypes]<EOL>_mask = (_variables.T == missingchar)<EOL>_datalist = [masked_array(a, mask=m, dtype=t, fill_value=f)<EOL>for (a, m, t, f) in zip(_variables.T, _mask, vartypes, mfillv)]<EOL>return fromarrays(_datalist, dtype=mdescr)<EOL>

Creates a mrecarray from data stored in the file `filename`.

    Parameters
    ----------
    filename : {file name/handle}
        Handle of an opened file.
    delimitor : {None, string}, optional
        Alphanumeric character used to separate columns in the file.
        If None, any (group of) white spacestring(s) will be used.
    commentchar : {'#', string}, optional
        Alphanumeric character used to mark the start of a comment.
    missingchar : {'', string}, optional
        String indicating missing data, and used to create the masks.
    varnames : {None, sequence}, optional
        Sequence of the variable names. If None, a list will be created from
        the first non empty line of the file.
    vartypes : {None, sequence}, optional
        Sequence of the variables dtypes. If None, it will be estimated from
        the first non-commented line.

    Ultra simple: the varnames are in the header, one line


def addfield(mrecord, newfield, newfieldname=None):

_data = mrecord._data<EOL>_mask = mrecord._mask<EOL>if newfieldname is None or newfieldname in reserved_fields:<EOL><INDENT>newfieldname = '<STR_LIT>' % len(_data.dtype)<EOL><DEDENT>newfield = ma.array(newfield)<EOL>newdtype = np.dtype(_data.dtype.descr + [(newfieldname, newfield.dtype)])<EOL>newdata = recarray(_data.shape, newdtype)<EOL>[newdata.setfield(_data.getfield(*f), *f)<EOL>for f in _data.dtype.fields.values()]<EOL>newdata.setfield(newfield._data, *newdata.dtype.fields[newfieldname])<EOL>newdata = newdata.view(MaskedRecords)<EOL>newmdtype = np.dtype([(n, bool_) for n in newdtype.names])<EOL>newmask = recarray(_data.shape, newmdtype)<EOL>[newmask.setfield(_mask.getfield(*f), *f)<EOL>for f in _mask.dtype.fields.values()]<EOL>newmask.setfield(getmaskarray(newfield),<EOL>*newmask.dtype.fields[newfieldname])<EOL>newdata._mask = newmask<EOL>return newdata<EOL>

Adds a new field to the masked record array, using `newfield` as data
and `newfieldname` as name. If `newfieldname` is None, the new field name is
set to 'fi', where `i` is the number of existing fields.


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


return self._mask<EOL>


<EOL>if self.ndim:<EOL><INDENT>return len(self._data)<EOL><DEDENT>return len(self.dtype)<EOL>


<EOL>if attr in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>self.__setmask__(val)<EOL>return<EOL><DEDENT>_localdict = object.__getattribute__(self, '<STR_LIT>')<EOL>newattr = attr not in _localdict<EOL>try:<EOL><INDENT>ret = object.__setattr__(self, attr, val)<EOL><DEDENT>except:<EOL><INDENT>fielddict = ndarray.__getattribute__(self, '<STR_LIT>').fields or {}<EOL>optinfo = ndarray.__getattribute__(self, '<STR_LIT>') or {}<EOL>if not (attr in fielddict or attr in optinfo):<EOL><INDENT>exctype, value = sys.exc_info()[:<NUM_LIT:2>]<EOL>raise exctype(value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fielddict = ndarray.__getattribute__(self, '<STR_LIT>').fields or {}<EOL>if attr not in fielddict:<EOL><INDENT>return ret<EOL><DEDENT>if newattr:         <EOL><INDENT>try:            <EOL><INDENT>object.__delattr__(self, attr)<EOL><DEDENT>except:<EOL><INDENT>return ret<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>res = fielddict[attr][:<NUM_LIT:2>]<EOL><DEDENT>except (TypeError, KeyError):<EOL><INDENT>raise AttributeError("<STR_LIT>" % attr)<EOL><DEDENT>if val is masked:<EOL><INDENT>_fill_value = _localdict['<STR_LIT>']<EOL>if _fill_value is not None:<EOL><INDENT>dval = _localdict['<STR_LIT>'][attr]<EOL><DEDENT>else:<EOL><INDENT>dval = val<EOL><DEDENT>mval = True<EOL><DEDENT>else:<EOL><INDENT>dval = filled(val)<EOL>mval = getmaskarray(val)<EOL><DEDENT>obj = ndarray.__getattribute__(self, '<STR_LIT>').setfield(dval, *res)<EOL>_localdict['<STR_LIT>'].__setitem__(attr, mval)<EOL>return obj<EOL>

Sets the attribute attr to the value val.


_localdict = self.__dict__<EOL>_mask = ndarray.__getattribute__(self, '<STR_LIT>')<EOL>_data = ndarray.view(self, _localdict['<STR_LIT>'])<EOL>if isinstance(indx, basestring):<EOL><INDENT>obj = _data[indx].view(MaskedArray)<EOL>obj._mask = _mask[indx]<EOL>obj._sharedmask = True<EOL>fval = _localdict['<STR_LIT>']<EOL>if fval is not None:<EOL><INDENT>obj._fill_value = fval[indx]<EOL><DEDENT>if not obj.ndim and obj._mask:<EOL><INDENT>return masked<EOL><DEDENT>return obj<EOL><DEDENT>obj = np.array(_data[indx], copy=False).view(mrecarray)<EOL>obj._mask = np.array(_mask[indx], copy=False).view(recarray)<EOL>return obj<EOL>

Returns all the fields sharing the same fieldname base.
The fieldname base is either `_data` or `_mask`.


MaskedArray.__setitem__(self, indx, value)<EOL>if isinstance(indx, basestring):<EOL><INDENT>self._mask[indx] = ma.getmaskarray(value)<EOL><DEDENT>


if self.size > <NUM_LIT:1>:<EOL><INDENT>mstr = ["<STR_LIT>" % "<STR_LIT:U+002C>".join([str(i) for i in s])<EOL>for s in zip(*[getattr(self, f) for f in self.dtype.names])]<EOL>return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(mstr)<EOL><DEDENT>else:<EOL><INDENT>mstr = ["<STR_LIT:%s>" % "<STR_LIT:U+002C>".join([str(i) for i in s])<EOL>for s in zip([getattr(self, f) for f in self.dtype.names])]<EOL>return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(mstr)<EOL><DEDENT>


_names = self.dtype.names<EOL>fmt = "<STR_LIT>" % (max([len(n) for n in _names]) + <NUM_LIT:4>,)<EOL>reprstr = [fmt % (f, getattr(self, f)) for f in self.dtype.names]<EOL>reprstr.insert(<NUM_LIT:0>, '<STR_LIT>')<EOL>reprstr.extend([fmt % ('<STR_LIT>', self.fill_value),<EOL>'<STR_LIT>'])<EOL>return str("<STR_LIT:\n>".join(reprstr))<EOL>


<EOL>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>dtype = np.dtype(dtype)<EOL>if dtype.fields is None:<EOL><INDENT>basetype = self.__class__.__bases__[<NUM_LIT:0>]<EOL>output = self.__array__().view(dtype, basetype)<EOL>output._update_from(self)<EOL><DEDENT>else:<EOL><INDENT>output = ndarray.view(self, dtype)<EOL><DEDENT>output._fill_value = None<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>mdtype = ma.make_mask_descr(output.dtype)<EOL>output._mask = self._mask.view(mdtype, ndarray)<EOL>output._mask.shape = output.shape<EOL><DEDENT>return output<EOL>


self._hardmask = True<EOL>


self._hardmask = False<EOL>


_localdict = self.__dict__<EOL>copied = self._data.copy().view(type(self))<EOL>copied._mask = self._mask.copy()<EOL>return copied<EOL>


if fill_value is not None:<EOL><INDENT>return self.filled(fill_value).tolist()<EOL><DEDENT>result = narray(self.filled().tolist(), dtype=object)<EOL>mask = narray(self._mask.tolist())<EOL>result[mask] = None<EOL>return result.tolist()<EOL>

Copy the data portion of the array to a hierarchical python
        list and returns that 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``.


state = (<NUM_LIT:1>,<EOL>self.shape,<EOL>self.dtype,<EOL>self.flags.fnc,<EOL>self._data.tobytes(),<EOL>self._mask.tobytes(),<EOL>self._fill_value,<EOL>)<EOL>return state<EOL>

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


(ver, shp, typ, isf, raw, msk, flv) = state<EOL>ndarray.__setstate__(self, (shp, typ, isf, raw))<EOL>mdtype = dtype([(k, bool_) for (k, _) in self.dtype.descr])<EOL>self.__dict__['<STR_LIT>'].__setstate__((shp, mdtype, 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 (_mrreconstruct,<EOL>(self.__class__, self._baseclass, (<NUM_LIT:0>,), '<STR_LIT:b>',),<EOL>self.__getstate__())<EOL>

Return a 3-tuple for pickling a MaskedArray.


if initialdoc is None:<EOL><INDENT>return<EOL><DEDENT>if note is None:<EOL><INDENT>return initialdoc<EOL><DEDENT>newdoc = """<STR_LIT>"""<EOL>return newdoc % (initialdoc, note)<EOL>

Adds a Notes section to an existing docstring.


try:<EOL><INDENT>sig = formatargspec(*getargspec(obj))<EOL><DEDENT>except TypeError as errmsg:<EOL><INDENT>sig = '<STR_LIT>'<EOL><INDENT>msg = "<STR_LIT>""<STR_LIT>"<EOL>warnings.warn(msg % (type(obj),<EOL>getattr(obj, '<STR_LIT>', '<STR_LIT>'),<EOL>errmsg))<EOL><DEDENT><DEDENT>return sig<EOL>


if hasattr(obj, '<STR_LIT>'):<EOL><INDENT>defval = _check_fill_value(None, obj.dtype)<EOL><DEDENT>elif isinstance(obj, np.dtype):<EOL><INDENT>if obj.subdtype:<EOL><INDENT>defval = default_filler.get(obj.subdtype[<NUM_LIT:0>].kind, '<STR_LIT:?>')<EOL><DEDENT>elif obj.kind in '<STR_LIT>':<EOL><INDENT>defval = default_filler.get(obj.str[<NUM_LIT:1>:], '<STR_LIT:?>')<EOL><DEDENT>else:<EOL><INDENT>defval = default_filler.get(obj.kind, '<STR_LIT:?>')<EOL><DEDENT><DEDENT>elif isinstance(obj, float):<EOL><INDENT>defval = default_filler['<STR_LIT:f>']<EOL><DEDENT>elif isinstance(obj, int) or isinstance(obj, long):<EOL><INDENT>defval = default_filler['<STR_LIT:i>']<EOL><DEDENT>elif isinstance(obj, str):<EOL><INDENT>defval = default_filler['<STR_LIT:S>']<EOL><DEDENT>elif isinstance(obj, unicode):<EOL><INDENT>defval = default_filler['<STR_LIT>']<EOL><DEDENT>elif isinstance(obj, complex):<EOL><INDENT>defval = default_filler['<STR_LIT:c>']<EOL><DEDENT>else:<EOL><INDENT>defval = default_filler['<STR_LIT:O>']<EOL><DEDENT>return defval<EOL>

Return the default fill value for the argument object.

The default filling value depends on the datatype of the input
array or the type of the input scalar:

   ========  ========
   datatype  default
   ========  ========
   bool      True
   int       999999
   float     1.e20
   complex   1.e20+0j
   object    '?'
   string    'N/A'
   ========  ========

Parameters
----------
obj : ndarray, dtype or scalar
    The array data-type or scalar for which the default fill value
    is returned.

Returns
-------
fill_value : scalar
    The default fill value.

Examples
--------
>>> np.ma.default_fill_value(1)
999999
>>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
1e+20
>>> np.ma.default_fill_value(np.dtype(complex))
(1e+20+0j)


errmsg = "<STR_LIT>"<EOL>if hasattr(obj, '<STR_LIT>'):<EOL><INDENT>return _recursive_extremum_fill_value(obj.dtype, min_filler)<EOL><DEDENT>elif isinstance(obj, float):<EOL><INDENT>return min_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, int):<EOL><INDENT>return min_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, long):<EOL><INDENT>return min_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, np.dtype):<EOL><INDENT>return min_filler[obj]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(errmsg)<EOL><DEDENT>

Return the maximum value that can be represented by the dtype of an object.

This function is useful for calculating a fill value suitable for
taking the minimum of an array with a given dtype.

Parameters
----------
obj : ndarray or dtype
    An object that can be queried for it's numeric type.

Returns
-------
val : scalar
    The maximum representable value.

Raises
------
TypeError
    If `obj` isn't a suitable numeric type.

See Also
--------
maximum_fill_value : The inverse function.
set_fill_value : Set the filling value of a masked array.
MaskedArray.fill_value : Return current fill value.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.minimum_fill_value(a)
127
>>> a = np.int32()
>>> ma.minimum_fill_value(a)
2147483647

An array of numeric data can also be passed.

>>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.minimum_fill_value(a)
127
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.minimum_fill_value(a)
inf


errmsg = "<STR_LIT>"<EOL>if hasattr(obj, '<STR_LIT>'):<EOL><INDENT>return _recursive_extremum_fill_value(obj.dtype, max_filler)<EOL><DEDENT>elif isinstance(obj, float):<EOL><INDENT>return max_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, int):<EOL><INDENT>return max_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, long):<EOL><INDENT>return max_filler[ntypes.typeDict['<STR_LIT>']]<EOL><DEDENT>elif isinstance(obj, np.dtype):<EOL><INDENT>return max_filler[obj]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(errmsg)<EOL><DEDENT>

Return the minimum value that can be represented by the dtype of an object.

This function is useful for calculating a fill value suitable for
taking the maximum of an array with a given dtype.

Parameters
----------
obj : {ndarray, dtype}
    An object that can be queried for it's numeric type.

Returns
-------
val : scalar
    The minimum representable value.

Raises
------
TypeError
    If `obj` isn't a suitable numeric type.

See Also
--------
minimum_fill_value : The inverse function.
set_fill_value : Set the filling value of a masked array.
MaskedArray.fill_value : Return current fill value.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.maximum_fill_value(a)
-128
>>> a = np.int32()
>>> ma.maximum_fill_value(a)
-2147483648

An array of numeric data can also be passed.

>>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.maximum_fill_value(a)
-128
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.maximum_fill_value(a)
-inf


ndtype = np.dtype(ndtype)<EOL>fields = ndtype.fields<EOL>if fill_value is None:<EOL><INDENT>if fields:<EOL><INDENT>descr = ndtype.descr<EOL>fill_value = np.array(_recursive_set_default_fill_value(descr),<EOL>dtype=ndtype,)<EOL><DEDENT>else:<EOL><INDENT>fill_value = default_fill_value(ndtype)<EOL><DEDENT><DEDENT>elif fields:<EOL><INDENT>fdtype = [(_[<NUM_LIT:0>], _[<NUM_LIT:1>]) for _ in ndtype.descr]<EOL>if isinstance(fill_value, (ndarray, np.void)):<EOL><INDENT>try:<EOL><INDENT>fill_value = np.array(fill_value, copy=False, dtype=fdtype)<EOL><DEDENT>except ValueError:<EOL><INDENT>err_msg = "<STR_LIT>"<EOL>raise ValueError(err_msg % (fill_value, fdtype))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>descr = ndtype.descr<EOL>fill_value = np.asarray(fill_value, dtype=object)<EOL>fill_value = np.array(_recursive_set_fill_value(fill_value, descr),<EOL>dtype=ndtype)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if isinstance(fill_value, basestring) and (ndtype.char not in '<STR_LIT>'):<EOL><INDENT>err_msg = "<STR_LIT>"<EOL>raise TypeError(err_msg % ndtype)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>fill_value = np.array(fill_value, copy=False, dtype=ndtype)<EOL><DEDENT>except OverflowError:<EOL><INDENT>err_msg = "<STR_LIT>"<EOL>raise TypeError(err_msg % (fill_value, ndtype))<EOL><DEDENT><DEDENT><DEDENT>return np.array(fill_value)<EOL>

Private function validating the given `fill_value` for the given dtype.

If fill_value is None, it is set to the default corresponding to the dtype
if this latter is standard (no fields). If the datatype is flexible (named
fields), fill_value is set to a tuple whose elements are the default fill
values corresponding to each field.

If fill_value is not None, its value is forced to the given dtype.


if isinstance(a, MaskedArray):<EOL><INDENT>a.set_fill_value(fill_value)<EOL><DEDENT>return<EOL>

Set the filling value of a, if a is a masked array.

This function changes the fill value of the masked array `a` in place.
If `a` is not a masked array, the function returns silently, without
doing anything.

Parameters
----------
a : array_like
    Input array.
fill_value : dtype
    Filling value. A consistency test is performed to make sure
    the value is compatible with the dtype of `a`.

Returns
-------
None
    Nothing returned by this function.

See Also
--------
maximum_fill_value : Return the default fill value for a dtype.
MaskedArray.fill_value : Return current fill value.
MaskedArray.set_fill_value : Equivalent method.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> a = ma.masked_where(a < 3, a)
>>> a
masked_array(data = [-- -- -- 3 4],
      mask = [ True  True  True False False],
      fill_value=999999)
>>> ma.set_fill_value(a, -999)
>>> a
masked_array(data = [-- -- -- 3 4],
      mask = [ True  True  True False False],
      fill_value=-999)

Nothing happens if `a` is not a masked array.

>>> a = range(5)
>>> a
[0, 1, 2, 3, 4]
>>> ma.set_fill_value(a, 100)
>>> a
[0, 1, 2, 3, 4]
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> ma.set_fill_value(a, 100)
>>> a
array([0, 1, 2, 3, 4])


if isinstance(a, MaskedArray):<EOL><INDENT>result = a.fill_value<EOL><DEDENT>else:<EOL><INDENT>result = default_fill_value(a)<EOL><DEDENT>return result<EOL>

Return the filling value of a, if any.  Otherwise, returns the
default filling value for that type.


t1 = get_fill_value(a)<EOL>t2 = get_fill_value(b)<EOL>if t1 == t2:<EOL><INDENT>return t1<EOL><DEDENT>return None<EOL>

Return the common filling value of two masked arrays, if any.

If ``a.fill_value == b.fill_value``, return the fill value,
otherwise return None.

Parameters
----------
a, b : MaskedArray
    The masked arrays for which to compare fill values.

Returns
-------
fill_value : scalar or None
    The common fill value, or None.

Examples
--------
>>> x = np.ma.array([0, 1.], fill_value=3)
>>> y = np.ma.array([0, 1.], fill_value=3)
>>> np.ma.common_fill_value(x, y)
3.0


if hasattr(a, '<STR_LIT>'):<EOL><INDENT>return a.filled(fill_value)<EOL><DEDENT>elif isinstance(a, ndarray):<EOL><INDENT>return a<EOL><DEDENT>elif isinstance(a, dict):<EOL><INDENT>return np.array(a, '<STR_LIT:O>')<EOL><DEDENT>else:<EOL><INDENT>return np.array(a)<EOL><DEDENT>

Return input as an array with masked data replaced by a fill value.

If `a` is not a `MaskedArray`, `a` itself is returned.
If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
``a.fill_value``.

Parameters
----------
a : MaskedArray or array_like
    An input object.
fill_value : scalar, optional
    Filling value. Default is None.

Returns
-------
a : ndarray
    The filled array.

See Also
--------
compressed

Examples
--------
>>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
...                                                   [1, 0, 0],
...                                                   [0, 0, 0]])
>>> x.filled()
array([[999999,      1,      2],
       [999999,      4,      5],
       [     6,      7,      8]])


if len(arrays) == <NUM_LIT:1>:<EOL><INDENT>arr = arrays[<NUM_LIT:0>]<EOL>if isinstance(arr, MaskedArray):<EOL><INDENT>rcls = type(arr)<EOL><DEDENT>else:<EOL><INDENT>rcls = MaskedArray<EOL><DEDENT><DEDENT>else:<EOL><INDENT>arrcls = [type(a) for a in arrays]<EOL>rcls = arrcls[<NUM_LIT:0>]<EOL>if not issubclass(rcls, MaskedArray):<EOL><INDENT>rcls = MaskedArray<EOL><DEDENT>for cls in arrcls[<NUM_LIT:1>:]:<EOL><INDENT>if issubclass(cls, rcls):<EOL><INDENT>rcls = cls<EOL><DEDENT><DEDENT><DEDENT>if rcls.__name__ == '<STR_LIT>':<EOL><INDENT>return MaskedArray<EOL><DEDENT>return rcls<EOL>

Return the youngest subclass of MaskedArray from a list of (masked) arrays.
In case of siblings, the first listed takes over.


try:<EOL><INDENT>data = a._data<EOL><DEDENT>except AttributeError:<EOL><INDENT>data = np.array(a, copy=False, subok=subok)<EOL><DEDENT>if not subok:<EOL><INDENT>return data.view(ndarray)<EOL><DEDENT>return data<EOL>

Return the data of a masked array as an ndarray.

Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``,
else return `a` as a ndarray or subclass (depending on `subok`) if not.

Parameters
----------
a : array_like
    Input ``MaskedArray``, alternatively a ndarray or a subclass thereof.
subok : bool
    Whether to force the output to be a `pure` ndarray (False) or to
    return a subclass of ndarray if appropriate (True, default).

See Also
--------
getmask : Return the mask of a masked array, or nomask.
getmaskarray : Return the mask of a masked array, or full array of False.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(data =
 [[1 --]
 [3 4]],
      mask =
 [[False  True]
 [False False]],
      fill_value=999999)
>>> ma.getdata(a)
array([[1, 2],
       [3, 4]])

Equivalently use the ``MaskedArray`` `data` attribute.

>>> a.data
array([[1, 2],
       [3, 4]])


def fix_invalid(a, mask=nomask, copy=True, fill_value=None):

a = masked_array(a, copy=copy, mask=mask, subok=True)<EOL>invalid = np.logical_not(np.isfinite(a._data))<EOL>if not invalid.any():<EOL><INDENT>return a<EOL><DEDENT>a._mask |= invalid<EOL>if fill_value is None:<EOL><INDENT>fill_value = a.fill_value<EOL><DEDENT>a._data[invalid] = fill_value<EOL>return a<EOL>

Return input with invalid data masked and replaced by a fill value.

Invalid data means values of `nan`, `inf`, etc.

Parameters
----------
a : array_like
    Input array, a (subclass of) ndarray.
copy : bool, optional
    Whether to use a copy of `a` (True) or to fix `a` in place (False).
    Default is True.
fill_value : scalar, optional
    Value used for fixing invalid data. Default is None, in which case
    the ``a.fill_value`` is used.

Returns
-------
b : MaskedArray
    The input array with invalid entries fixed.

Notes
-----
A copy is performed by default.

Examples
--------
>>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3)
>>> x
masked_array(data = [-- -1.0 nan inf],
             mask = [ True False False False],
       fill_value = 1e+20)
>>> np.ma.fix_invalid(x)
masked_array(data = [-- -1.0 -- --],
             mask = [ True False  True  True],
       fill_value = 1e+20)

>>> fixed = np.ma.fix_invalid(x)
>>> fixed.data
array([  1.00000000e+00,  -1.00000000e+00,   1.00000000e+20,
         1.00000000e+20])
>>> x.data
array([  1.,  -1.,  NaN,  Inf])


<EOL>if datatype.names:<EOL><INDENT>descr = []<EOL>for name in datatype.names:<EOL><INDENT>field = datatype.fields[name]<EOL>if len(field) == <NUM_LIT:3>:<EOL><INDENT>name = (field[-<NUM_LIT:1>], name)<EOL><DEDENT>descr.append((name, _recursive_make_descr(field[<NUM_LIT:0>], newtype)))<EOL><DEDENT>return descr<EOL><DEDENT>elif datatype.subdtype:<EOL><INDENT>mdescr = list(datatype.subdtype)<EOL>mdescr[<NUM_LIT:0>] = newtype<EOL>return tuple(mdescr)<EOL><DEDENT>else:<EOL><INDENT>return newtype<EOL><DEDENT>

Private function allowing recursion in make_descr.


<EOL>if not isinstance(ndtype, np.dtype):<EOL><INDENT>ndtype = np.dtype(ndtype)<EOL><DEDENT>return np.dtype(_recursive_make_descr(ndtype, np.bool))<EOL>

Construct a dtype description list from a given dtype.

Returns a new dtype object, with the type of all fields in `ndtype` to a
boolean type. Field names are not altered.

Parameters
----------
ndtype : dtype
    The dtype to convert.

Returns
-------
result : dtype
    A dtype that looks like `ndtype`, the type of all fields is boolean.

Examples
--------
>>> import numpy.ma as ma
>>> dtype = np.dtype({'names':['foo', 'bar'],
                      'formats':[np.float32, np.int]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i4')])
>>> ma.make_mask_descr(dtype)
dtype([('foo', '|b1'), ('bar', '|b1')])
>>> ma.make_mask_descr(np.float32)
<type 'numpy.bool_'>


return getattr(a, '<STR_LIT>', nomask)<EOL>

Return the mask of a masked array, or nomask.

Return the mask of `a` as an ndarray if `a` is a `MaskedArray` and the
mask is not `nomask`, else return `nomask`. To guarantee a full array
of booleans of the same shape as a, use `getmaskarray`.

Parameters
----------
a : array_like
    Input `MaskedArray` for which the mask is required.

See Also
--------
getdata : Return the data of a masked array as an ndarray.
getmaskarray : Return the mask of a masked array, or full array of False.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(data =
 [[1 --]
 [3 4]],
      mask =
 [[False  True]
 [False False]],
      fill_value=999999)
>>> ma.getmask(a)
array([[False,  True],
       [False, False]], dtype=bool)

Equivalently use the `MaskedArray` `mask` attribute.

>>> a.mask
array([[False,  True],
       [False, False]], dtype=bool)

Result when mask == `nomask`

>>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(data =
 [[1 2]
 [3 4]],
      mask =
 False,
      fill_value=999999)
>>> ma.nomask
False
>>> ma.getmask(b) == ma.nomask
True
>>> b.mask == ma.nomask
True


mask = getmask(arr)<EOL>if mask is nomask:<EOL><INDENT>mask = make_mask_none(np.shape(arr), getdata(arr).dtype)<EOL><DEDENT>return mask<EOL>

Return the mask of a masked array, or full boolean array of False.

Return the mask of `arr` as an ndarray if `arr` is a `MaskedArray` and
the mask is not `nomask`, else return a full boolean array of False of
the same shape as `arr`.

Parameters
----------
arr : array_like
    Input `MaskedArray` for which the mask is required.

See Also
--------
getmask : Return the mask of a masked array, or nomask.
getdata : Return the data of a masked array as an ndarray.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(data =
 [[1 --]
 [3 4]],
      mask =
 [[False  True]
 [False False]],
      fill_value=999999)
>>> ma.getmaskarray(a)
array([[False,  True],
       [False, False]], dtype=bool)

Result when mask == ``nomask``

>>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(data =
 [[1 2]
 [3 4]],
      mask =
 False,
      fill_value=999999)
>>> >ma.getmaskarray(b)
array([[False, False],
       [False, False]], dtype=bool)


try:<EOL><INDENT>return m.dtype.type is MaskType<EOL><DEDENT>except AttributeError:<EOL><INDENT>return False<EOL><DEDENT>

Return True if m is a valid, standard mask.

This function does not check the contents of the input, only that the
type is MaskType. In particular, this function returns False if the
mask has a flexible dtype.

Parameters
----------
m : array_like
    Array to test.

Returns
-------
result : bool
    True if `m.dtype.type` is MaskType, False otherwise.

See Also
--------
isMaskedArray : Test whether input is an instance of MaskedArray.

Examples
--------
>>> import numpy.ma as ma
>>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> m
masked_array(data = [-- 1 -- 2 3],
      mask = [ True False  True False False],
      fill_value=999999)
>>> ma.is_mask(m)
False
>>> ma.is_mask(m.mask)
True

Input must be an ndarray (or have similar attributes)
for it to be considered a valid mask.

>>> m = [False, True, False]
>>> ma.is_mask(m)
False
>>> m = np.array([False, True, False])
>>> m
array([False,  True, False], dtype=bool)
>>> ma.is_mask(m)
True

Arrays with complex dtypes don't return True.

>>> dtype = np.dtype({'names':['monty', 'pithon'],
                      'formats':[np.bool, np.bool]})
>>> dtype
dtype([('monty', '|b1'), ('pithon', '|b1')])
>>> m = np.array([(True, False), (False, True), (True, False)],
                 dtype=dtype)
>>> m
array([(True, False), (False, True), (True, False)],
      dtype=[('monty', '|b1'), ('pithon', '|b1')])
>>> ma.is_mask(m)
False


def make_mask(m, copy=False, shrink=True, dtype=MaskType):

if m is nomask:<EOL><INDENT>return nomask<EOL><DEDENT>elif isinstance(m, ndarray):<EOL><INDENT>m = filled(m, True)<EOL>dtype = make_mask_descr(dtype)<EOL>if m.dtype == dtype:<EOL><INDENT>if copy:<EOL><INDENT>result = m.copy()<EOL><DEDENT>else:<EOL><INDENT>result = m<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result = np.array(m, dtype=dtype, copy=copy)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result = np.array(filled(m, True), dtype=MaskType)<EOL><DEDENT>if shrink and (not result.dtype.names) and (not result.any()):<EOL><INDENT>return nomask<EOL><DEDENT>else:<EOL><INDENT>return result<EOL><DEDENT>

Create a boolean mask from an array.

Return `m` as a boolean mask, creating a copy if necessary or requested.
The function can accept any sequence that is convertible to integers,
or ``nomask``.  Does not require that contents must be 0s and 1s, values
of 0 are interepreted as False, everything else as True.

Parameters
----------
m : array_like
    Potential mask.
copy : bool, optional
    Whether to return a copy of `m` (True) or `m` itself (False).
shrink : bool, optional
    Whether to shrink `m` to ``nomask`` if all its values are False.
dtype : dtype, optional
    Data-type of the output mask. By default, the output mask has
    a dtype of MaskType (bool). If the dtype is flexible, each field
    has a boolean dtype.

Returns
-------
result : ndarray
    A boolean mask derived from `m`.

Examples
--------
>>> import numpy.ma as ma
>>> m = [True, False, True, True]
>>> ma.make_mask(m)
array([ True, False,  True,  True], dtype=bool)
>>> m = [1, 0, 1, 1]
>>> ma.make_mask(m)
array([ True, False,  True,  True], dtype=bool)
>>> m = [1, 0, 2, -3]
>>> ma.make_mask(m)
array([ True, False,  True,  True], dtype=bool)

Effect of the `shrink` parameter.

>>> m = np.zeros(4)
>>> m
array([ 0.,  0.,  0.,  0.])
>>> ma.make_mask(m)
False
>>> ma.make_mask(m, shrink=False)
array([False, False, False, False], dtype=bool)

Using a flexible `dtype`.

>>> m = [1, 0, 1, 1]
>>> n = [0, 1, 0, 0]
>>> arr = []
>>> for man, mouse in zip(m, n):
...     arr.append((man, mouse))
>>> arr
[(1, 0), (0, 1), (1, 0), (1, 0)]
>>> dtype = np.dtype({'names':['man', 'mouse'],
                      'formats':[np.int, np.int]})
>>> arr = np.array(arr, dtype=dtype)
>>> arr
array([(1, 0), (0, 1), (1, 0), (1, 0)],
      dtype=[('man', '<i4'), ('mouse', '<i4')])
>>> ma.make_mask(arr, dtype=dtype)
array([(True, False), (False, True), (True, False), (True, False)],
      dtype=[('man', '|b1'), ('mouse', '|b1')])


if dtype is None:<EOL><INDENT>result = np.zeros(newshape, dtype=MaskType)<EOL><DEDENT>else:<EOL><INDENT>result = np.zeros(newshape, dtype=make_mask_descr(dtype))<EOL><DEDENT>return result<EOL>

Return a boolean mask of the given shape, filled with False.

This function returns a boolean ndarray with all entries False, that can
be used in common mask manipulations. If a complex dtype is specified, the
type of each field is converted to a boolean type.

Parameters
----------
newshape : tuple
    A tuple indicating the shape of the mask.
dtype : {None, dtype}, optional
    If None, use a MaskType instance. Otherwise, use a new datatype with
    the same fields as `dtype`, converted to boolean types.

Returns
-------
result : ndarray
    An ndarray of appropriate shape and dtype, filled with False.

See Also
--------
make_mask : Create a boolean mask from an array.
make_mask_descr : Construct a dtype description list from a given dtype.

Examples
--------
>>> import numpy.ma as ma
>>> ma.make_mask_none((3,))
array([False, False, False], dtype=bool)

Defining a more complex dtype.

>>> dtype = np.dtype({'names':['foo', 'bar'],
                      'formats':[np.float32, np.int]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i4')])
>>> ma.make_mask_none((3,), dtype=dtype)
array([(False, False), (False, False), (False, False)],
      dtype=[('foo', '|b1'), ('bar', '|b1')])


def mask_or (m1, m2, copy=False, shrink=True):

def _recursive_mask_or(m1, m2, newmask):<EOL><INDENT>names = m1.dtype.names<EOL>for name in names:<EOL><INDENT>current1 = m1[name]<EOL>if current1.dtype.names:<EOL><INDENT>_recursive_mask_or(current1, m2[name], newmask[name])<EOL><DEDENT>else:<EOL><INDENT>umath.logical_or(current1, m2[name], newmask[name])<EOL><DEDENT><DEDENT>return<EOL><DEDENT>if (m1 is nomask) or (m1 is False):<EOL><INDENT>dtype = getattr(m2, '<STR_LIT>', MaskType)<EOL>return make_mask(m2, copy=copy, shrink=shrink, dtype=dtype)<EOL><DEDENT>if (m2 is nomask) or (m2 is False):<EOL><INDENT>dtype = getattr(m1, '<STR_LIT>', MaskType)<EOL>return make_mask(m1, copy=copy, shrink=shrink, dtype=dtype)<EOL><DEDENT>if m1 is m2 and is_mask(m1):<EOL><INDENT>return m1<EOL><DEDENT>(dtype1, dtype2) = (getattr(m1, '<STR_LIT>', None), getattr(m2, '<STR_LIT>', None))<EOL>if (dtype1 != dtype2):<EOL><INDENT>raise ValueError("<STR_LIT>" % (dtype1, dtype2))<EOL><DEDENT>if dtype1.names:<EOL><INDENT>newmask = np.empty_like(m1)<EOL>_recursive_mask_or(m1, m2, newmask)<EOL>return newmask<EOL><DEDENT>return make_mask(umath.logical_or(m1, m2), copy=copy, shrink=shrink)<EOL>

Combine two masks with the ``logical_or`` operator.

The result may be a view on `m1` or `m2` if the other is `nomask`
(i.e. False).

Parameters
----------
m1, m2 : array_like
    Input masks.
copy : bool, optional
    If copy is False and one of the inputs is `nomask`, return a view
    of the other input mask. Defaults to False.
shrink : bool, optional
    Whether to shrink the output to `nomask` if all its values are
    False. Defaults to True.

Returns
-------
mask : output mask
    The result masks values that are masked in either `m1` or `m2`.

Raises
------
ValueError
    If `m1` and `m2` have different flexible dtypes.

Examples
--------
>>> m1 = np.ma.make_mask([0, 1, 1, 0])
>>> m2 = np.ma.make_mask([1, 0, 0, 0])
>>> np.ma.mask_or(m1, m2)
array([ True,  True,  True, False], dtype=bool)


<EOL>def _flatmask(mask):<EOL><INDENT>"<STR_LIT>"<EOL>mnames = mask.dtype.names<EOL>if mnames:<EOL><INDENT>return [flatten_mask(mask[name]) for name in mnames]<EOL><DEDENT>else:<EOL><INDENT>return mask<EOL><DEDENT><DEDENT>def _flatsequence(sequence):<EOL><INDENT>"<STR_LIT>"<EOL>try:<EOL><INDENT>for element in sequence:<EOL><INDENT>if hasattr(element, '<STR_LIT>'):<EOL><INDENT>for f in _flatsequence(element):<EOL><INDENT>yield f<EOL><DEDENT><DEDENT>else:<EOL><INDENT>yield element<EOL><DEDENT><DEDENT><DEDENT>except TypeError:<EOL><INDENT>yield sequence<EOL><DEDENT><DEDENT>mask = np.asarray(mask)<EOL>flattened = _flatsequence(_flatmask(mask))<EOL>return np.array([_ for _ in flattened], dtype=bool)<EOL>

Returns a completely flattened version of the mask, where nested fields
are collapsed.

Parameters
----------
mask : array_like
    Input array, which will be interpreted as booleans.

Returns
-------
flattened_mask : ndarray of bools
    The flattened input.

Examples
--------
>>> mask = np.array([0, 0, 1], dtype=np.bool)
>>> flatten_mask(mask)
array([False, False,  True], dtype=bool)

>>> mask = np.array([(0, 0), (0, 1)], dtype=[('a', bool), ('b', bool)])
>>> flatten_mask(mask)
array([False, False, False,  True], dtype=bool)

>>> mdtype = [('a', bool), ('b', [('ba', bool), ('bb', bool)])]
>>> mask = np.array([(0, (0, 0)), (0, (0, 1))], dtype=mdtype)
>>> flatten_mask(mask)
array([False, False, False, False, False,  True], dtype=bool)


if mask is not nomask:<EOL><INDENT>return mask.all(axis=axis)<EOL><DEDENT>return nomask<EOL>

Check whether there are masked values along the given axis


def masked_where(condition, a, copy=True):

<EOL>cond = make_mask(condition)<EOL>a = np.array(a, copy=copy, subok=True)<EOL>(cshape, ashape) = (cond.shape, a.shape)<EOL>if cshape and cshape != ashape:<EOL><INDENT>raise IndexError("<STR_LIT>"<EOL>"<STR_LIT>" % (cshape, ashape))<EOL><DEDENT>if hasattr(a, '<STR_LIT>'):<EOL><INDENT>cond = mask_or(cond, a._mask)<EOL>cls = type(a)<EOL><DEDENT>else:<EOL><INDENT>cls = MaskedArray<EOL><DEDENT>result = a.view(cls)<EOL>result._mask = cond<EOL>return result<EOL>

Mask an array where a condition is met.

Return `a` as an array masked where `condition` is True.
Any masked values of `a` or `condition` are also masked in the output.

Parameters
----------
condition : array_like
    Masking condition.  When `condition` tests floating point values for
    equality, consider using ``masked_values`` instead.
a : array_like
    Array to mask.
copy : bool
    If True (default) make a copy of `a` in the result.  If False modify
    `a` in place and return a view.

Returns
-------
result : MaskedArray
    The result of masking `a` where `condition` is True.

See Also
--------
masked_values : Mask using floating point equality.
masked_equal : Mask where equal to a given value.
masked_not_equal : Mask where `not` equal to a given value.
masked_less_equal : Mask where less than or equal to a given value.
masked_greater_equal : Mask where greater than or equal to a given value.
masked_less : Mask where less than a given value.
masked_greater : Mask where greater than a given value.
masked_inside : Mask inside a given interval.
masked_outside : Mask outside a given interval.
masked_invalid : Mask invalid values (NaNs or infs).

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_where(a <= 2, a)
masked_array(data = [-- -- -- 3],
      mask = [ True  True  True False],
      fill_value=999999)

Mask array `b` conditional on `a`.

>>> b = ['a', 'b', 'c', 'd']
>>> ma.masked_where(a == 2, b)
masked_array(data = [a b -- d],
      mask = [False False  True False],
      fill_value=N/A)

Effect of the `copy` argument.

>>> c = ma.masked_where(a <= 2, a)
>>> c
masked_array(data = [-- -- -- 3],
      mask = [ True  True  True False],
      fill_value=999999)
>>> c[0] = 99
>>> c
masked_array(data = [99 -- -- 3],
      mask = [False  True  True False],
      fill_value=999999)
>>> a
array([0, 1, 2, 3])
>>> c = ma.masked_where(a <= 2, a, copy=False)
>>> c[0] = 99
>>> c
masked_array(data = [99 -- -- 3],
      mask = [False  True  True False],
      fill_value=999999)
>>> a
array([99,  1,  2,  3])

When `condition` or `a` contain masked values.

>>> a = np.arange(4)
>>> a = ma.masked_where(a == 2, a)
>>> a
masked_array(data = [0 1 -- 3],
      mask = [False False  True False],
      fill_value=999999)
>>> b = np.arange(4)
>>> b = ma.masked_where(b == 0, b)
>>> b
masked_array(data = [-- 1 2 3],
      mask = [ True False False False],
      fill_value=999999)
>>> ma.masked_where(a == 3, b)
masked_array(data = [-- 1 -- --],
      mask = [ True False  True  True],
      fill_value=999999)


def masked_greater(x, value, copy=True):

return masked_where(greater(x, value), x, copy=copy)<EOL>

Mask an array where greater than a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x > value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater(a, 2)
masked_array(data = [0 1 2 --],
      mask = [False False False  True],
      fill_value=999999)


def masked_greater_equal(x, value, copy=True):

return masked_where(greater_equal(x, value), x, copy=copy)<EOL>

Mask an array where greater than or equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x >= value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater_equal(a, 2)
masked_array(data = [0 1 -- --],
      mask = [False False  True  True],
      fill_value=999999)


return masked_where(less(x, value), x, copy=copy)<EOL>

Mask an array where less than a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x < value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less(a, 2)
masked_array(data = [-- -- 2 3],
      mask = [ True  True False False],
      fill_value=999999)


def masked_less_equal(x, value, copy=True):

return masked_where(less_equal(x, value), x, copy=copy)<EOL>

Mask an array where less than or equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x <= value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less_equal(a, 2)
masked_array(data = [-- -- -- 3],
      mask = [ True  True  True False],
      fill_value=999999)


def masked_not_equal(x, value, copy=True):

return masked_where(not_equal(x, value), x, copy=copy)<EOL>

Mask an array where `not` equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x != value).

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_not_equal(a, 2)
masked_array(data = [-- -- 2 --],
      mask = [ True  True False  True],
      fill_value=999999)


<EOL>output = masked_where(equal(x, value), x, copy=copy)<EOL>output.fill_value = value<EOL>return output<EOL>

Mask an array where equal to a given value.

This function is a shortcut to ``masked_where``, with
`condition` = (x == value).  For floating point arrays,
consider using ``masked_values(x, value)``.

See Also
--------
masked_where : Mask where a condition is met.
masked_values : Mask using floating point equality.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_equal(a, 2)
masked_array(data = [0 1 -- 3],
      mask = [False False  True False],
      fill_value=999999)


def masked_inside(x, v1, v2, copy=True):

if v2 < v1:<EOL><INDENT>(v1, v2) = (v2, v1)<EOL><DEDENT>xf = filled(x)<EOL>condition = (xf >= v1) & (xf <= v2)<EOL>return masked_where(condition, x, copy=copy)<EOL>

Mask an array inside a given interval.

Shortcut to ``masked_where``, where `condition` is True for `x` inside
the interval [v1,v2] (v1 <= x <= v2).  The boundaries `v1` and `v2`
can be given in either order.

See Also
--------
masked_where : Mask where a condition is met.

Notes
-----
The array `x` is prefilled with its filling value.

Examples
--------
>>> import numpy.ma as ma
>>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
>>> ma.masked_inside(x, -0.3, 0.3)
masked_array(data = [0.31 1.2 -- -- -0.4 -1.1],
      mask = [False False  True  True False False],
      fill_value=1e+20)

The order of `v1` and `v2` doesn't matter.

>>> ma.masked_inside(x, 0.3, -0.3)
masked_array(data = [0.31 1.2 -- -- -0.4 -1.1],
      mask = [False False  True  True False False],
      fill_value=1e+20)


def masked_outside(x, v1, v2, copy=True):

if v2 < v1:<EOL><INDENT>(v1, v2) = (v2, v1)<EOL><DEDENT>xf = filled(x)<EOL>condition = (xf < v1) | (xf > v2)<EOL>return masked_where(condition, x, copy=copy)<EOL>

Mask an array outside a given interval.

Shortcut to ``masked_where``, where `condition` is True for `x` outside
the interval [v1,v2] (x < v1)|(x > v2).
The boundaries `v1` and `v2` can be given in either order.

See Also
--------
masked_where : Mask where a condition is met.

Notes
-----
The array `x` is prefilled with its filling value.

Examples
--------
>>> import numpy.ma as ma
>>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
>>> ma.masked_outside(x, -0.3, 0.3)
masked_array(data = [-- -- 0.01 0.2 -- --],
      mask = [ True  True False False  True  True],
      fill_value=1e+20)

The order of `v1` and `v2` doesn't matter.

>>> ma.masked_outside(x, 0.3, -0.3)
masked_array(data = [-- -- 0.01 0.2 -- --],
      mask = [ True  True False False  True  True],
      fill_value=1e+20)


def masked_object(x, value, copy=True, shrink=True):

if isMaskedArray(x):<EOL><INDENT>condition = umath.equal(x._data, value)<EOL>mask = x._mask<EOL><DEDENT>else:<EOL><INDENT>condition = umath.equal(np.asarray(x), value)<EOL>mask = nomask<EOL><DEDENT>mask = mask_or(mask, make_mask(condition, shrink=shrink))<EOL>return masked_array(x, mask=mask, copy=copy, fill_value=value)<EOL>

Mask the array `x` where the data are exactly equal to value.

This function is similar to `masked_values`, but only suitable
for object arrays: for floating point, use `masked_values` instead.

Parameters
----------
x : array_like
    Array to mask
value : object
    Comparison value
copy : {True, False}, optional
    Whether to return a copy of `x`.
shrink : {True, False}, optional
    Whether to collapse a mask full of False to nomask

Returns
-------
result : MaskedArray
    The result of masking `x` where equal to `value`.

See Also
--------
masked_where : Mask where a condition is met.
masked_equal : Mask where equal to a given value (integers).
masked_values : Mask using floating point equality.

Examples
--------
>>> import numpy.ma as ma
>>> food = np.array(['green_eggs', 'ham'], dtype=object)
>>> # don't eat spoiled food
>>> eat = ma.masked_object(food, 'green_eggs')
>>> print eat
[-- ham]
>>> # plain ol` ham is boring
>>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object)
>>> eat = ma.masked_object(fresh_food, 'green_eggs')
>>> print eat
[cheese ham pineapple]

Note that `mask` is set to ``nomask`` if possible.

>>> eat
masked_array(data = [cheese ham pineapple],
      mask = False,
      fill_value=?)


def masked_values(x, value, rtol=<NUM_LIT>, atol=<NUM_LIT>, copy=True, shrink=True):

mabs = umath.absolute<EOL>xnew = filled(x, value)<EOL>if issubclass(xnew.dtype.type, np.floating):<EOL><INDENT>condition = umath.less_equal(mabs(xnew - value), atol + rtol * mabs(value))<EOL>mask = getattr(x, '<STR_LIT>', nomask)<EOL><DEDENT>else:<EOL><INDENT>condition = umath.equal(xnew, value)<EOL>mask = nomask<EOL><DEDENT>mask = mask_or(mask, make_mask(condition, shrink=shrink))<EOL>return masked_array(xnew, mask=mask, copy=copy, fill_value=value)<EOL>

Mask using floating point equality.

Return a MaskedArray, masked where the data in array `x` are approximately
equal to `value`, i.e. where the following condition is True

(abs(x - value) <= atol+rtol*abs(value))

The fill_value is set to `value` and the mask is set to ``nomask`` if
possible.  For integers, consider using ``masked_equal``.

Parameters
----------
x : array_like
    Array to mask.
value : float
    Masking value.
rtol : float, optional
    Tolerance parameter.
atol : float, optional
    Tolerance parameter (1e-8).
copy : bool, optional
    Whether to return a copy of `x`.
shrink : bool, optional
    Whether to collapse a mask full of False to ``nomask``.

Returns
-------
result : MaskedArray
    The result of masking `x` where approximately equal to `value`.

See Also
--------
masked_where : Mask where a condition is met.
masked_equal : Mask where equal to a given value (integers).

Examples
--------
>>> import numpy.ma as ma
>>> x = np.array([1, 1.1, 2, 1.1, 3])
>>> ma.masked_values(x, 1.1)
masked_array(data = [1.0 -- 2.0 -- 3.0],
      mask = [False  True False  True False],
      fill_value=1.1)

Note that `mask` is set to ``nomask`` if possible.

>>> ma.masked_values(x, 1.5)
masked_array(data = [ 1.   1.1  2.   1.1  3. ],
      mask = False,
      fill_value=1.5)

For integers, the fill value will be different in general to the
result of ``masked_equal``.

>>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> ma.masked_values(x, 2)
masked_array(data = [0 1 -- 3 4],
      mask = [False False  True False False],
      fill_value=2)
>>> ma.masked_equal(x, 2)
masked_array(data = [0 1 -- 3 4],
      mask = [False False  True False False],
      fill_value=999999)


a = np.array(a, copy=copy, subok=True)<EOL>mask = getattr(a, '<STR_LIT>', None)<EOL>if mask is not None:<EOL><INDENT>condition = ~(np.isfinite(getdata(a)))<EOL>if mask is not nomask:<EOL><INDENT>condition |= mask<EOL><DEDENT>cls = type(a)<EOL><DEDENT>else:<EOL><INDENT>condition = ~(np.isfinite(a))<EOL>cls = MaskedArray<EOL><DEDENT>result = a.view(cls)<EOL>result._mask = condition<EOL>return result<EOL>

Mask an array where invalid values occur (NaNs or infs).

This function is a shortcut to ``masked_where``, with
`condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved.
Only applies to arrays with a dtype where NaNs or infs make sense
(i.e. floating point types), but accepts any array_like object.

See Also
--------
masked_where : Mask where a condition is met.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.arange(5, dtype=np.float)
>>> a[2] = np.NaN
>>> a[3] = np.PINF
>>> a
array([  0.,   1.,  NaN,  Inf,   4.])
>>> ma.masked_invalid(a)
masked_array(data = [0.0 1.0 -- -- 4.0],
      mask = [False False  True  True False],
      fill_value=1e+20)


def _recursive_printoption(result, mask, printopt):

names = result.dtype.names<EOL>for name in names:<EOL><INDENT>(curdata, curmask) = (result[name], mask[name])<EOL>if curdata.dtype.names:<EOL><INDENT>_recursive_printoption(curdata, curmask, printopt)<EOL><DEDENT>else:<EOL><INDENT>np.copyto(curdata, printopt, where=curmask)<EOL><DEDENT><DEDENT>return<EOL>

Puts printoptions in result where mask is True.
Private function allowing for recursion


def _recursive_filled(a, mask, fill_value):

names = a.dtype.names<EOL>for name in names:<EOL><INDENT>current = a[name]<EOL>if current.dtype.names:<EOL><INDENT>_recursive_filled(current, mask[name], fill_value[name])<EOL><DEDENT>else:<EOL><INDENT>np.copyto(current, fill_value[name], where=mask[name])<EOL><DEDENT><DEDENT>

Recursively fill `a` with `fill_value`.
Private function


<EOL>def flatten_sequence(iterable):<EOL><INDENT>"""<STR_LIT>"""<EOL>for elm in iter(iterable):<EOL><INDENT>if hasattr(elm, '<STR_LIT>'):<EOL><INDENT>for f in flatten_sequence(elm):<EOL><INDENT>yield f<EOL><DEDENT><DEDENT>else:<EOL><INDENT>yield elm<EOL><DEDENT><DEDENT><DEDENT>a = np.asanyarray(a)<EOL>inishape = a.shape<EOL>a = a.ravel()<EOL>if isinstance(a, MaskedArray):<EOL><INDENT>out = np.array([tuple(flatten_sequence(d.item())) for d in a._data])<EOL>out = out.view(MaskedArray)<EOL>out._mask = np.array([tuple(flatten_sequence(d.item()))<EOL>for d in getmaskarray(a)])<EOL><DEDENT>else:<EOL><INDENT>out = np.array([tuple(flatten_sequence(d.item())) for d in a])<EOL><DEDENT>if len(inishape) > <NUM_LIT:1>:<EOL><INDENT>newshape = list(out.shape)<EOL>newshape[<NUM_LIT:0>] = inishape<EOL>out.shape = tuple(flatten_sequence(newshape))<EOL><DEDENT>return out<EOL>

Flatten a structured array.

The data type of the output is chosen such that it can represent all of the
(nested) fields.

Parameters
----------
a : structured array

Returns
-------
output : masked array or ndarray
    A flattened masked array if the input is a masked array, otherwise a
    standard ndarray.

Examples
--------
>>> ndtype = [('a', int), ('b', float)]
>>> a = np.array([(1, 1), (2, 2)], dtype=ndtype)
>>> flatten_structured_array(a)
array([[1., 1.],
       [2., 2.]])


def _mareconstruct(subtype, baseclass, baseshape, basetype,):

_data = ndarray.__new__(baseclass, baseshape, basetype)<EOL>_mask = ndarray.__new__(ndarray, baseshape, make_mask_descr(basetype))<EOL>return subtype.__new__(subtype, _data, mask=_mask, dtype=basetype,)<EOL>

Internal function that builds a new MaskedArray from the
    information stored in a pickle.


return isinstance(x, MaskedArray)<EOL>

Test whether input is an instance of MaskedArray.

This function returns True if `x` is an instance of MaskedArray
and returns False otherwise.  Any object is accepted as input.

Parameters
----------
x : object
    Object to test.

Returns
-------
result : bool
    True if `x` is a MaskedArray.

See Also
--------
isMA : Alias to isMaskedArray.
isarray : Alias to isMaskedArray.

Examples
--------
>>> import numpy.ma as ma
>>> a = np.eye(3, 3)
>>> a
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> m = ma.masked_values(a, 0)
>>> m
masked_array(data =
 [[1.0 -- --]
 [-- 1.0 --]
 [-- -- 1.0]],
      mask =
 [[False  True  True]
 [ True False  True]
 [ True  True False]],
      fill_value=0.0)
>>> ma.isMaskedArray(a)
False
>>> ma.isMaskedArray(m)
True
>>> ma.isMaskedArray([0, 1, 2])
False


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

<EOL>return MaskedArray(data, mask=mask, dtype=dtype, copy=copy, subok=subok,<EOL>keep_mask=keep_mask, hard_mask=hard_mask,<EOL>fill_value=fill_value, ndmin=ndmin, shrink=shrink)<EOL>

array(data, dtype=None, copy=False, order=False, mask=nomask,
             fill_value=None, keep_mask=True, hard_mask=False, shrink=True,
             subok=True, ndmin=0)

    Acts as shortcut to MaskedArray, with options in a different order
    for convenience.  And backwards compatibility...


m = getmask(x)<EOL>if m is nomask:<EOL><INDENT>return False<EOL><DEDENT>elif m.any():<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Determine whether input has masked values.

Accepts any object as input, but always returns False unless the
input is a MaskedArray containing masked values.

Parameters
----------
x : array_like
    Array to check for masked values.

Returns
-------
result : bool
    True if `x` is a MaskedArray with masked values, False otherwise.

Examples
--------
>>> import numpy.ma as ma
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> x
masked_array(data = [-- 1 -- 2 3],
      mask = [ True False  True False False],
      fill_value=999999)
>>> ma.is_masked(x)
True
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 42)
>>> x
masked_array(data = [0 1 0 2 3],
      mask = False,
      fill_value=999999)
>>> ma.is_masked(x)
False

Always returns False if `x` isn't a MaskedArray.

>>> x = [False, True, False]
>>> ma.is_masked(x)
False
>>> x = 'a string'
>>> ma.is_masked(x)
False


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

try:<EOL><INDENT>return obj.ptp(axis, out=out, fill_value=fill_value)<EOL><DEDENT>except (AttributeError, TypeError):<EOL><INDENT>return asanyarray(obj).ptp(axis=axis, fill_value=fill_value, out=out)<EOL><DEDENT>

a.ptp(axis=None) =  a.max(axis)-a.min(axis)


if third is not None:<EOL><INDENT>raise MaskError("<STR_LIT>")<EOL><DEDENT>ma = getmask(a)<EOL>mb = getmask(b)<EOL>m = mask_or(ma, mb)<EOL>fa = getdata(a)<EOL>fb = getdata(b)<EOL>if isinstance(a, MaskedArray):<EOL><INDENT>basetype = type(a)<EOL><DEDENT>else:<EOL><INDENT>basetype = MaskedArray<EOL><DEDENT>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = np.where(m, fa, umath.power(fa, fb)).view(basetype)<EOL><DEDENT>result._update_from(a)<EOL>invalid = np.logical_not(np.isfinite(result.view(ndarray)))<EOL>if m is not nomask:<EOL><INDENT>if not (result.ndim):<EOL><INDENT>return masked<EOL><DEDENT>result._mask = np.logical_or(m, invalid)<EOL><DEDENT>if invalid.any():<EOL><INDENT>if not result.ndim:<EOL><INDENT>return masked<EOL><DEDENT>elif result._mask is nomask:<EOL><INDENT>result._mask = invalid<EOL><DEDENT>result._data[invalid] = result.fill_value<EOL><DEDENT>return result<EOL>

Returns element-wise base array raised to power from second array.

This is the masked array version of `numpy.power`. For details see
`numpy.power`.

See Also
--------
numpy.power

Notes
-----
The *out* argument to `numpy.power` is not supported, `third` has to be
None.


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

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

Function version of the eponymous method.


def argmin(a, axis=None, fill_value=None):

if fill_value is None:<EOL><INDENT>fill_value = default_fill_value(a)<EOL><DEDENT>d = filled(a, fill_value)<EOL>return d.argmin(axis=axis)<EOL>


def argmax(a, axis=None, fill_value=None):

if fill_value is None:<EOL><INDENT>fill_value = default_fill_value(a)<EOL>try:<EOL><INDENT>fill_value = -fill_value<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>d = filled(a, fill_value)<EOL>return d.argmax(axis=axis)<EOL>


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

a = narray(a, copy=True, subok=True)<EOL>if axis is None:<EOL><INDENT>a = a.flatten()<EOL>axis = <NUM_LIT:0><EOL><DEDENT>if fill_value is None:<EOL><INDENT>if endwith:<EOL><INDENT>if np.issubdtype(a.dtype, np.floating):<EOL><INDENT>filler = np.nan<EOL><DEDENT>else:<EOL><INDENT>filler = minimum_fill_value(a)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filler = maximum_fill_value(a)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>filler = fill_value<EOL><DEDENT>sindx = filled(a, filler).argsort(axis=axis, kind=kind, order=order)<EOL>if a.ndim == <NUM_LIT:1>:<EOL><INDENT>indx = sindx<EOL><DEDENT>else:<EOL><INDENT>indx = np.meshgrid(*[np.arange(x) for x in a.shape], sparse=True,<EOL>indexing='<STR_LIT>')<EOL>indx[axis] = sindx<EOL><DEDENT>return a[indx]<EOL>


if not isinstance(x, MaskedArray):<EOL><INDENT>x = asanyarray(x)<EOL><DEDENT>return x.compressed()<EOL>

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

This function is equivalent to calling the "compressed" method of a
`MaskedArray`, see `MaskedArray.compressed` for details.

See Also
--------
MaskedArray.compressed
    Equivalent method.


d = np.concatenate([getdata(a) for a in arrays], axis)<EOL>rcls = get_masked_subclass(*arrays)<EOL>data = d.view(rcls)<EOL>for x in arrays:<EOL><INDENT>if getmask(x) is not nomask:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return data<EOL><DEDENT>dm = np.concatenate([getmaskarray(a) for a in arrays], axis)<EOL><INDENT>shrink = numpy.logical_or.reduce([getattr(a,'<STR_LIT>',True) for a in arrays])<EOL>if shrink and not dm.any():<EOL><DEDENT>if not dm.dtype.fields and not dm.any():<EOL><INDENT>data._mask = nomask<EOL><DEDENT>else:<EOL><INDENT>data._mask = dm.reshape(d.shape)<EOL><DEDENT>return data<EOL>

Concatenate a sequence of arrays along the given axis.

Parameters
----------
arrays : sequence of array_like
    The arrays must have the same shape, except in the dimension
    corresponding to `axis` (the first, by default).
axis : int, optional
    The axis along which the arrays will be joined. Default is 0.

Returns
-------
result : MaskedArray
    The concatenated array with any masked entries preserved.

See Also
--------
numpy.concatenate : Equivalent function in the top-level NumPy module.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.arange(3)
>>> a[1] = ma.masked
>>> b = ma.arange(2, 5)
>>> a
masked_array(data = [0 -- 2],
             mask = [False  True False],
       fill_value = 999999)
>>> b
masked_array(data = [2 3 4],
             mask = False,
       fill_value = 999999)
>>> ma.concatenate([a, b])
masked_array(data = [0 -- 2 2 3 4],
             mask = [False  True False False False False],
       fill_value = 999999)


output = np.diag(v, k).view(MaskedArray)<EOL>if getmask(v) is not nomask:<EOL><INDENT>output._mask = np.diag(v._mask, k)<EOL><DEDENT>return output<EOL>

Extract a diagonal or construct a diagonal array.

This function is the equivalent of `numpy.diag` that takes masked
values into account, see `numpy.diag` for details.

See Also
--------
numpy.diag : Equivalent function for ndarrays.


result = n_expand_dims(x, axis)<EOL>if isinstance(x, MaskedArray):<EOL><INDENT>new_shape = result.shape<EOL>result = x.view()<EOL>result.shape = new_shape<EOL>if result._mask is not nomask:<EOL><INDENT>result._mask.shape = new_shape<EOL><DEDENT><DEDENT>return result<EOL>

Expand the shape of an array.

Expands the shape of the array by including a new axis before the one
specified by the `axis` parameter. This function behaves the same as
`numpy.expand_dims` but preserves masked elements.

See Also
--------
numpy.expand_dims : Equivalent function in top-level NumPy module.

Examples
--------
>>> import numpy.ma as ma
>>> x = ma.array([1, 2, 4])
>>> x[1] = ma.masked
>>> x
masked_array(data = [1 -- 4],
             mask = [False  True False],
       fill_value = 999999)
>>> np.expand_dims(x, axis=0)
array([[1, 2, 4]])
>>> ma.expand_dims(x, axis=0)
masked_array(data =
 [[1 -- 4]],
             mask =
 [[False  True False]],
       fill_value = 999999)

The same result can be achieved using slicing syntax with `np.newaxis`.

>>> x[np.newaxis, :]
masked_array(data =
 [[1 -- 4]],
             mask =
 [[False  True False]],
       fill_value = 999999)


m = getmask(a)<EOL>if m is nomask:<EOL><INDENT>d = umath.left_shift(filled(a), n)<EOL>return masked_array(d)<EOL><DEDENT>else:<EOL><INDENT>d = umath.left_shift(filled(a, <NUM_LIT:0>), n)<EOL>return masked_array(d, mask=m)<EOL><DEDENT>

Shift the bits of an integer to the left.

This is the masked array version of `numpy.left_shift`, for details
see that function.

See Also
--------
numpy.left_shift


m = getmask(a)<EOL>if m is nomask:<EOL><INDENT>d = umath.right_shift(filled(a), n)<EOL>return masked_array(d)<EOL><DEDENT>else:<EOL><INDENT>d = umath.right_shift(filled(a, <NUM_LIT:0>), n)<EOL>return masked_array(d, mask=m)<EOL><DEDENT>

Shift the bits of an integer to the right.

This is the masked array version of `numpy.right_shift`, for details
see that function.

See Also
--------
numpy.right_shift


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

<EOL>try:<EOL><INDENT>return a.put(indices, values, mode=mode)<EOL><DEDENT>except AttributeError:<EOL><INDENT>return narray(a, copy=False).put(indices, values, mode=mode)<EOL><DEDENT>

Set storage-indexed locations to corresponding values.

This function is equivalent to `MaskedArray.put`, see that method
for details.

See Also
--------
MaskedArray.put


<EOL>if not isinstance(a, MaskedArray):<EOL><INDENT>a = a.view(MaskedArray)<EOL><DEDENT>(valdata, valmask) = (getdata(values), getmask(values))<EOL>if getmask(a) is nomask:<EOL><INDENT>if valmask is not nomask:<EOL><INDENT>a._sharedmask = True<EOL>a._mask = make_mask_none(a.shape, a.dtype)<EOL>np.copyto(a._mask, valmask, where=mask)<EOL><DEDENT><DEDENT>elif a._hardmask:<EOL><INDENT>if valmask is not nomask:<EOL><INDENT>m = a._mask.copy()<EOL>np.copyto(m, valmask, where=mask)<EOL>a.mask |= m<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if valmask is nomask:<EOL><INDENT>valmask = getmaskarray(values)<EOL><DEDENT>np.copyto(a._mask, valmask, where=mask)<EOL><DEDENT>np.copyto(a._data, valdata, where=mask)<EOL>return<EOL>

Changes elements of an array based on conditional and input values.

This is the masked array version of `numpy.putmask`, for details see
`numpy.putmask`.

See Also
--------
numpy.putmask

Notes
-----
Using a masked array as `values` will **not** transform a `ndarray` into
a `MaskedArray`.


<EOL>try:<EOL><INDENT>return a.transpose(axes)<EOL><DEDENT>except AttributeError:<EOL><INDENT>return narray(a, copy=False).transpose(axes).view(MaskedArray)<EOL><DEDENT>

Permute the dimensions of an array.

This function is exactly equivalent to `numpy.transpose`.

See Also
--------
numpy.transpose : Equivalent function in top-level NumPy module.

Examples
--------
>>> import numpy.ma as ma
>>> x = ma.arange(4).reshape((2,2))
>>> x[1, 1] = ma.masked
>>>> x
masked_array(data =
 [[0 1]
 [2 --]],
             mask =
 [[False False]
 [False  True]],
       fill_value = 999999)
>>> ma.transpose(x)
masked_array(data =
 [[0 2]
 [1 --]],
             mask =
 [[False False]
 [False  True]],
       fill_value = 999999)


def reshape(a, new_shape, order='<STR_LIT:C>'):

<EOL>try:<EOL><INDENT>return a.reshape(new_shape, order=order)<EOL><DEDENT>except AttributeError:<EOL><INDENT>_tmp = narray(a, copy=False).reshape(new_shape, order=order)<EOL>return _tmp.view(MaskedArray)<EOL><DEDENT>

Returns an array containing the same data with a new shape.

Refer to `MaskedArray.reshape` for full documentation.

See Also
--------
MaskedArray.reshape : equivalent function


<EOL>m = getmask(x)<EOL>if m is not nomask:<EOL><INDENT>m = np.resize(m, new_shape)<EOL><DEDENT>result = np.resize(x, new_shape).view(get_masked_subclass(x))<EOL>if result.ndim:<EOL><INDENT>result._mask = m<EOL><DEDENT>return result<EOL>

Return a new masked array with the specified size and shape.

This is the masked equivalent of the `numpy.resize` function. The new
array is filled with repeated copies of `x` (in the order that the
data are stored in memory). If `x` is masked, the new array will be
masked, and the new mask will be a repetition of the old one.

See Also
--------
numpy.resize : Equivalent function in the top level NumPy module.

Examples
--------
>>> import numpy.ma as ma
>>> a = ma.array([[1, 2] ,[3, 4]])
>>> a[0, 1] = ma.masked
>>> a
masked_array(data =
 [[1 --]
 [3 4]],
             mask =
 [[False  True]
 [False False]],
       fill_value = 999999)
>>> np.resize(a, (3, 3))
array([[1, 2, 3],
       [4, 1, 2],
       [3, 4, 1]])
>>> ma.resize(a, (3, 3))
masked_array(data =
 [[1 -- 3]
 [4 1 --]
 [3 4 1]],
             mask =
 [[False  True False]
 [False False  True]
 [False False False]],
       fill_value = 999999)

A MaskedArray is always returned, regardless of the input type.

>>> a = np.array([[1, 2] ,[3, 4]])
>>> ma.resize(a, (3, 3))
masked_array(data =
 [[1 2 3]
 [4 1 2]
 [3 4 1]],
             mask =
 False,
       fill_value = 999999)


return np.rank(getdata(obj))<EOL>

maskedarray version of the numpy function.


return np.shape(getdata(obj))<EOL>


return np.size(getdata(obj), axis)<EOL>


if x is None and y is None:<EOL><INDENT>return filled(condition, <NUM_LIT:0>).nonzero()<EOL><DEDENT>elif x is None or y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>fc = filled(condition, <NUM_LIT:0>).astype(MaskType)<EOL>notfc = np.logical_not(fc)<EOL>xv = getdata(x)<EOL>yv = getdata(y)<EOL>if x is masked:<EOL><INDENT>ndtype = yv.dtype<EOL><DEDENT>elif y is masked:<EOL><INDENT>ndtype = xv.dtype<EOL><DEDENT>else:<EOL><INDENT>ndtype = np.find_common_type([xv.dtype, yv.dtype], [])<EOL><DEDENT>d = np.empty(fc.shape, dtype=ndtype).view(MaskedArray)<EOL>_data = d._data<EOL>np.copyto(_data, xv.astype(ndtype), where=fc)<EOL>np.copyto(_data, yv.astype(ndtype), where=notfc)<EOL>_mask = d._mask = np.zeros(fc.shape, dtype=MaskType)<EOL>np.copyto(_mask, getmask(x), where=fc)<EOL>np.copyto(_mask, getmask(y), where=notfc)<EOL>_mask |= getmaskarray(condition)<EOL>if not _mask.any():<EOL><INDENT>d._mask = nomask<EOL><DEDENT>return d<EOL>

Return a masked array with elements from x or y, depending on condition.

Returns a masked array, shaped like condition, where the elements
are from `x` when `condition` is True, and from `y` otherwise.
If neither `x` nor `y` are given, the function returns a tuple of
indices where `condition` is True (the result of
``condition.nonzero()``).

Parameters
----------
condition : array_like, bool
    The condition to meet. For each True element, yield the corresponding
    element from `x`, otherwise from `y`.
x, y : array_like, optional
    Values from which to choose. `x` and `y` need to have the same shape
    as condition, or be broadcast-able to that shape.

Returns
-------
out : MaskedArray or tuple of ndarrays
    The resulting masked array if `x` and `y` were given, otherwise
    the result of ``condition.nonzero()``.

See Also
--------
numpy.where : Equivalent function in the top-level NumPy module.

Examples
--------
>>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
...                                                    [1, 0, 1],
...                                                    [0, 1, 0]])
>>> print x
[[0.0 -- 2.0]
 [-- 4.0 --]
 [6.0 -- 8.0]]
>>> np.ma.where(x > 5)    # return the indices where x > 5
(array([2, 2]), array([0, 2]))

>>> print np.ma.where(x > 5, x, -3.1416)
[[-3.1416 -- -3.1416]
 [-- -3.1416 --]
 [6.0 -- 8.0]]


def choose (indices, choices, out=None, mode='<STR_LIT>'):

def fmask (x):<EOL><INDENT>"<STR_LIT>"<EOL>if x is masked:<EOL><INDENT>return True<EOL><DEDENT>return filled(x)<EOL><DEDENT>def nmask (x):<EOL><INDENT>"<STR_LIT>"<EOL>if x is masked:<EOL><INDENT>return True<EOL><DEDENT>return getmask(x)<EOL><DEDENT>c = filled(indices, <NUM_LIT:0>)<EOL>masks = [nmask(x) for x in choices]<EOL>data = [fmask(x) for x in choices]<EOL>outputmask = np.choose(c, masks, mode=mode)<EOL>outputmask = make_mask(mask_or(outputmask, getmask(indices)),<EOL>copy=<NUM_LIT:0>, shrink=True)<EOL>d = np.choose(c, data, mode=mode, out=out).view(MaskedArray)<EOL>if out is not None:<EOL><INDENT>if isinstance(out, MaskedArray):<EOL><INDENT>out.__setmask__(outputmask)<EOL><DEDENT>return out<EOL><DEDENT>d.__setmask__(outputmask)<EOL>return d<EOL>

Use an index array to construct a new array from a set of choices.

Given an array of integers and a set of n choice arrays, this method
will create a new array that merges each of the choice arrays.  Where a
value in `a` is i, the new array will have the value that choices[i]
contains in the same place.

Parameters
----------
a : ndarray of ints
    This array must contain integers in ``[0, n-1]``, where n is the
    number of choices.
choices : sequence of arrays
    Choice arrays. The index array and all of the choices should be
    broadcastable to the same shape.
out : array, optional
    If provided, the result will be inserted into this array. It should
    be of the appropriate shape and `dtype`.
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

Returns
-------
merged_array : array

See Also
--------
choose : equivalent function

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


def round_(a, decimals=<NUM_LIT:0>, out=None):

if out is None:<EOL><INDENT>return np.round_(a, decimals, out)<EOL><DEDENT>else:<EOL><INDENT>np.round_(getdata(a), decimals, out)<EOL>if hasattr(out, '<STR_LIT>'):<EOL><INDENT>out._mask = getmask(a)<EOL><DEDENT>return out<EOL><DEDENT>

Return a copy of a, rounded to 'decimals' places.

When 'decimals' is negative, it specifies the number of positions
to the left of the decimal point.  The real and imaginary parts of
complex numbers are rounded separately. Nothing is done if the
array is not of float type and 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
    Number of decimals to round to. May be negative.
out : array_like
    Existing array to use for output.
    If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!


fa = filled(a, <NUM_LIT:0>)<EOL>fb = filled(b, <NUM_LIT:0>)<EOL>if len(fa.shape) == <NUM_LIT:0>:<EOL><INDENT>fa.shape = (<NUM_LIT:1>,)<EOL><DEDENT>if len(fb.shape) == <NUM_LIT:0>:<EOL><INDENT>fb.shape = (<NUM_LIT:1>,)<EOL><DEDENT>return np.inner(fa, fb).view(MaskedArray)<EOL>

Returns the inner product of a and b for arrays of floating point types.

Like the generic NumPy equivalent the product sum is over the last dimension
of a and b.

Notes
-----
The first argument is not conjugated.


fa = filled(a, <NUM_LIT:0>).ravel()<EOL>fb = filled(b, <NUM_LIT:0>).ravel()<EOL>d = np.outer(fa, fb)<EOL>ma = getmask(a)<EOL>mb = getmask(b)<EOL>if ma is nomask and mb is nomask:<EOL><INDENT>return masked_array(d)<EOL><DEDENT>ma = getmaskarray(a)<EOL>mb = getmaskarray(b)<EOL>m = make_mask(<NUM_LIT:1> - np.outer(<NUM_LIT:1> - ma, <NUM_LIT:1> - mb), copy=<NUM_LIT:0>)<EOL>return masked_array(d, mask=m)<EOL>


m = mask_or(getmask(a), getmask(b))<EOL>if m is nomask:<EOL><INDENT>x = getdata(a)<EOL>y = getdata(b)<EOL>d = umath.equal(x, y)<EOL>return d.all()<EOL><DEDENT>elif fill_value:<EOL><INDENT>x = getdata(a)<EOL>y = getdata(b)<EOL>d = umath.equal(x, y)<EOL>dm = array(d, mask=m, copy=False)<EOL>return dm.filled(True).all(None)<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Return True if all entries of a and b are equal, using
fill_value as a truth value where either or both are masked.

Parameters
----------
a, b : array_like
    Input arrays to compare.
fill_value : bool, optional
    Whether masked values in a or b are considered equal (True) or not
    (False).

Returns
-------
y : bool
    Returns True if the two arrays are equal within the given
    tolerance, False otherwise. If either array contains NaN,
    then False is returned.

See Also
--------
all, any
numpy.ma.allclose

Examples
--------
>>> a = ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
>>> a
masked_array(data = [10000000000.0 1e-07 --],
      mask = [False False  True],
      fill_value=1e+20)

>>> b = array([1e10, 1e-7, -42.0])
>>> b
array([  1.00000000e+10,   1.00000000e-07,  -4.20000000e+01])
>>> ma.allequal(a, b, fill_value=False)
False
>>> ma.allequal(a, b)
True


def allclose (a, b, masked_equal=True, rtol=<NUM_LIT>, atol=<NUM_LIT>):

x = masked_array(a, copy=False)<EOL>y = masked_array(b, copy=False)<EOL>dtype = np.result_type(y, <NUM_LIT:1.>)<EOL>if y.dtype != dtype:<EOL><INDENT>y = masked_array(y, dtype=dtype, copy=False)<EOL><DEDENT>m = mask_or(getmask(x), getmask(y))<EOL>xinf = np.isinf(masked_array(x, copy=False, mask=m)).filled(False)<EOL>if not np.all(xinf == filled(np.isinf(y), False)):<EOL><INDENT>return False<EOL><DEDENT>if not np.any(xinf):<EOL><INDENT>d = filled(umath.less_equal(umath.absolute(x - y),<EOL>atol + rtol * umath.absolute(y)),<EOL>masked_equal)<EOL>return np.all(d)<EOL><DEDENT>if not np.all(filled(x[xinf] == y[xinf], masked_equal)):<EOL><INDENT>return False<EOL><DEDENT>x = x[~xinf]<EOL>y = y[~xinf]<EOL>d = filled(umath.less_equal(umath.absolute(x - y),<EOL>atol + rtol * umath.absolute(y)),<EOL>masked_equal)<EOL>return np.all(d)<EOL>

Returns True if two arrays are element-wise equal within a tolerance.

This function is equivalent to `allclose` except that masked values
are treated as equal (default) or unequal, depending on the `masked_equal`
argument.

Parameters
----------
a, b : array_like
    Input arrays to compare.
masked_equal : bool, optional
    Whether masked values in `a` and `b` are considered equal (True) or not
    (False). They are considered equal by default.
rtol : float, optional
    Relative tolerance. The relative difference is equal to ``rtol * b``.
    Default is 1e-5.
atol : float, optional
    Absolute tolerance. The absolute difference is equal to `atol`.
    Default is 1e-8.

Returns
-------
y : bool
    Returns True if the two arrays are equal within the given
    tolerance, False otherwise. If either array contains NaN, then
    False is returned.

See Also
--------
all, any
numpy.allclose : the non-masked `allclose`.

Notes
-----
If the following equation is element-wise True, then `allclose` returns
True::

  absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))

Return True if all elements of `a` and `b` are equal subject to
given tolerances.

Examples
--------
>>> a = ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
>>> a
masked_array(data = [10000000000.0 1e-07 --],
             mask = [False False  True],
       fill_value = 1e+20)
>>> b = ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
>>> ma.allclose(a, b)
False

>>> a = ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
>>> ma.allclose(a, b)
True
>>> ma.allclose(a, b, masked_equal=False)
False

Masked values are not compared directly.

>>> a = ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1])
>>> ma.allclose(a, b)
True
>>> ma.allclose(a, b, masked_equal=False)
False


return masked_array(a, dtype=dtype, copy=False, keep_mask=True, subok=False)<EOL>

Convert the input to a masked array of the given data-type.

No copy is performed if the input is already an `ndarray`. If `a` is
a subclass of `MaskedArray`, a base class `MaskedArray` is returned.

Parameters
----------
a : array_like
    Input data, in any form that can be converted to a masked array. This
    includes lists, lists of tuples, tuples, tuples of tuples, tuples
    of lists, ndarrays and masked arrays.
dtype : dtype, optional
    By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
    Whether to use row-major ('C') or column-major ('FORTRAN') memory
    representation.  Default is 'C'.

Returns
-------
out : MaskedArray
    Masked array interpretation of `a`.

See Also
--------
asanyarray : Similar to `asarray`, but conserves subclasses.

Examples
--------
>>> x = np.arange(10.).reshape(2, 5)
>>> x
array([[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.]])
>>> np.ma.asarray(x)
masked_array(data =
 [[ 0.  1.  2.  3.  4.]
 [ 5.  6.  7.  8.  9.]],
             mask =
 False,
       fill_value = 1e+20)
>>> type(np.ma.asarray(x))
<class 'numpy.ma.core.MaskedArray'>


return masked_array(a, dtype=dtype, copy=False, keep_mask=True, subok=True)<EOL>

Convert the input to a masked array, conserving subclasses.

If `a` is a subclass of `MaskedArray`, its class is conserved.
No copy is performed if the input is already an `ndarray`.

Parameters
----------
a : array_like
    Input data, in any form that can be converted to an array.
dtype : dtype, optional
    By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
    Whether to use row-major ('C') or column-major ('FORTRAN') memory
    representation.  Default is 'C'.

Returns
-------
out : MaskedArray
    MaskedArray interpretation of `a`.

See Also
--------
asarray : Similar to `asanyarray`, but does not conserve subclass.

Examples
--------
>>> x = np.arange(10.).reshape(2, 5)
>>> x
array([[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.]])
>>> np.ma.asanyarray(x)
masked_array(data =
 [[ 0.  1.  2.  3.  4.]
 [ 5.  6.  7.  8.  9.]],
             mask =
 False,
       fill_value = 1e+20)
>>> type(np.ma.asanyarray(x))
<class 'numpy.ma.core.MaskedArray'>


if not hasattr(F, '<STR_LIT>'):<EOL><INDENT>F = open(F, '<STR_LIT:w>')<EOL><DEDENT>return pickle.dump(a, F)<EOL>

Pickle a masked array to a file.

This is a wrapper around ``cPickle.dump``.

Parameters
----------
a : MaskedArray
    The array to be pickled.
F : str or file-like object
    The file to pickle `a` to. If a string, the full path to the file.


return pickle.dumps(a)<EOL>

Return a string corresponding to the pickling of a masked array.

This is a wrapper around ``cPickle.dumps``.

Parameters
----------
a : MaskedArray
    The array for which the string representation of the pickle is
    returned.


if not hasattr(F, '<STR_LIT>'):<EOL><INDENT>F = open(F, '<STR_LIT:r>')<EOL><DEDENT>return pickle.load(F)<EOL>

Wrapper around ``cPickle.load`` which accepts either a file-like object
or a filename.

Parameters
----------
F : str or file
    The file or file name to load.

See Also
--------
dump : Pickle an array

Notes
-----
This is different from `numpy.load`, which does not use cPickle but loads
the NumPy binary .npy format.


return pickle.loads(strg)<EOL>

Load a pickle from the current string.

The result of ``cPickle.loads(strg)`` is returned.

Parameters
----------
strg : str
    The string to load.

See Also
--------
dumps : Return a string corresponding to the pickling of a masked array.


return masked_array(fxarray['<STR_LIT>'], mask=fxarray['<STR_LIT>'])<EOL>

Build a masked array from a suitable flexible-type array.

The input array has to have a data-type with ``_data`` and ``_mask``
fields. This type of array is output by `MaskedArray.toflex`.

Parameters
----------
fxarray : ndarray
    The structured input array, containing ``_data`` and ``_mask``
    fields. If present, other fields are discarded.

Returns
-------
result : MaskedArray
    The constructed masked array.

See Also
--------
MaskedArray.toflex : Build a flexible-type array from a masked array.

Examples
--------
>>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[0] + [1, 0] * 4)
>>> rec = x.toflex()
>>> rec
array([[(0, False), (1, True), (2, False)],
       [(3, True), (4, False), (5, True)],
       [(6, False), (7, True), (8, False)]],
      dtype=[('_data', '<i4'), ('_mask', '|b1')])
>>> x2 = np.ma.fromflex(rec)
>>> x2
masked_array(data =
 [[0 -- 2]
 [-- 4 --]
 [6 -- 8]],
             mask =
 [[False  True False]
 [ True False  True]
 [False  True False]],
       fill_value = 999999)

Extra fields can be present in the structured array but are discarded:

>>> dt = [('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')]
>>> rec2 = np.zeros((2, 2), dtype=dt)
>>> rec2
array([[(0, False, 0.0), (0, False, 0.0)],
       [(0, False, 0.0), (0, False, 0.0)]],
      dtype=[('_data', '<i4'), ('_mask', '|b1'), ('field3', '<f4')])
>>> y = np.ma.fromflex(rec2)
>>> y
masked_array(data =
 [[0 0]
 [0 0]],
             mask =
 [[False False]
 [False False]],
       fill_value = 999999)


return concatenate([a, b], axis)<EOL>

Append values to the end of an array.

    .. versionadded:: 1.9.0

    Parameters
    ----------
    arr : array_like
        Values are appended to a copy of this array.
    values : array_like
        These values are appended to a copy of `arr`.  It must be of the
        correct shape (the same shape as `arr`, excluding `axis`).  If `axis`
        is not specified, `values` can be any shape and will be flattened
        before use.
    axis : int, optional
        The axis along which `values` are appended.  If `axis` is not given,
        both `arr` and `values` are flattened before use.

    Returns
    -------
    append : MaskedArray
        A copy of `arr` with `values` appended to `axis`.  Note that `append`
        does not occur in-place: a new array is allocated and filled.  If
        `axis` is None, the result is a flattened array.

    See Also
    --------
    numpy.append : Equivalent function in the top-level NumPy module.

    Examples
    --------
    >>> import numpy.ma as ma
    >>> a = ma.masked_values([1, 2, 3], 2)
    >>> b = ma.masked_values([[4, 5, 6], [7, 8, 9]], 7)
    >>> print(ma.append(a, b))
    [1 -- 3 4 5 6 -- 8 9]


if (a > b):<EOL><INDENT>(a, b) = (b, a)<EOL><DEDENT>self.a = a<EOL>self.b = b<EOL>

domain_check_interval(a,b)(x) = true where x < a or y > b


return umath.logical_or(umath.greater (x, self.b),<EOL>umath.less(x, self.a))<EOL>


self.eps = eps<EOL>

domain_tan(eps) = true where abs(cos(x)) < eps)


return umath.less(umath.absolute(umath.cos(x)), self.eps)<EOL>


self.critical_value = critical_value<EOL>


return umath.less_equal(x, self.critical_value)<EOL>


DomainGreaterEqual(v)(x) = true where x < v


return umath.less(x, self.critical_value)<EOL>


def __init__ (self, mufunc, fill=<NUM_LIT:0>, domain=None):

self.f = mufunc<EOL>self.fill = fill<EOL>self.domain = domain<EOL>self.__doc__ = getattr(mufunc, "<STR_LIT>", str(mufunc))<EOL>self.__name__ = getattr(mufunc, "<STR_LIT>", str(mufunc))<EOL>ufunc_domain[mufunc] = domain<EOL>ufunc_fills[mufunc] = fill<EOL>

_MaskedUnaryOperation(aufunc, fill=0, domain=None)
            aufunc(fill) must be defined
            self(x) returns aufunc(x)
            with masked values where domain(x) is true or getmask(x) is true.


def __call__ (self, a, *args, **kwargs):

d = getdata(a)<EOL>if self.domain is not None:<EOL><INDENT>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = self.f(d, *args, **kwargs)<EOL><DEDENT>m = ~umath.isfinite(result)<EOL>m |= self.domain(d)<EOL>m |= getmask(a)<EOL><DEDENT>else:<EOL><INDENT>result = self.f(d, *args, **kwargs)<EOL>m = getmask(a)<EOL><DEDENT>if not result.ndim:<EOL><INDENT>if m:<EOL><INDENT>return masked<EOL><DEDENT>return result<EOL><DEDENT>if m is not nomask:<EOL><INDENT>try:<EOL><INDENT>np.copyto(result, d, where=m)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if isinstance(a, MaskedArray):<EOL><INDENT>subtype = type(a)<EOL><DEDENT>else:<EOL><INDENT>subtype = MaskedArray<EOL><DEDENT>result = result.view(subtype)<EOL>result._mask = m<EOL>result._update_from(a)<EOL>return result<EOL>


def __init__ (self, mbfunc, fillx=<NUM_LIT:0>, filly=<NUM_LIT:0>):

self.f = mbfunc<EOL>self.fillx = fillx<EOL>self.filly = filly<EOL>self.__doc__ = getattr(mbfunc, "<STR_LIT>", str(mbfunc))<EOL>self.__name__ = getattr(mbfunc, "<STR_LIT>", str(mbfunc))<EOL>ufunc_domain[mbfunc] = None<EOL>ufunc_fills[mbfunc] = (fillx, filly)<EOL>

abfunc(fillx, filly) must be defined.
           abfunc(x, filly) = x for all x to enable reduce.


def __call__ (self, a, b, *args, **kwargs):

<EOL>(da, db) = (getdata(a, subok=False), getdata(b, subok=False))<EOL>(ma, mb) = (getmask(a), getmask(b))<EOL>if ma is nomask:<EOL><INDENT>if mb is nomask:<EOL><INDENT>m = nomask<EOL><DEDENT>else:<EOL><INDENT>m = umath.logical_or(getmaskarray(a), mb)<EOL><DEDENT><DEDENT>elif mb is nomask:<EOL><INDENT>m = umath.logical_or(ma, getmaskarray(b))<EOL><DEDENT>else:<EOL><INDENT>m = umath.logical_or(ma, mb)<EOL><DEDENT>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = self.f(da, db, *args, **kwargs)<EOL><DEDENT>if result is NotImplemented:<EOL><INDENT>return NotImplemented<EOL><DEDENT>if not result.ndim:<EOL><INDENT>if m:<EOL><INDENT>return masked<EOL><DEDENT>return result<EOL><DEDENT>if m is not nomask:<EOL><INDENT>np.copyto(result, da, casting='<STR_LIT>', where=m)<EOL><DEDENT>result = result.view(get_masked_subclass(a, b))<EOL>result._mask = m<EOL>if isinstance(b, MaskedArray):<EOL><INDENT>if isinstance(a, MaskedArray):<EOL><INDENT>result._update_from(a)<EOL><DEDENT>else:<EOL><INDENT>result._update_from(b)<EOL><DEDENT><DEDENT>elif isinstance(a, MaskedArray):<EOL><INDENT>result._update_from(a)<EOL><DEDENT>return result<EOL>


def reduce(self, target, axis=<NUM_LIT:0>, dtype=None):

if isinstance(target, MaskedArray):<EOL><INDENT>tclass = type(target)<EOL><DEDENT>else:<EOL><INDENT>tclass = MaskedArray<EOL><DEDENT>m = getmask(target)<EOL>t = filled(target, self.filly)<EOL>if t.shape == ():<EOL><INDENT>t = t.reshape(<NUM_LIT:1>)<EOL>if m is not nomask:<EOL><INDENT>m = make_mask(m, copy=<NUM_LIT:1>)<EOL>m.shape = (<NUM_LIT:1>,)<EOL><DEDENT><DEDENT>if m is nomask:<EOL><INDENT>return self.f.reduce(t, axis).view(tclass)<EOL><DEDENT>t = t.view(tclass)<EOL>t._mask = m<EOL>tr = self.f.reduce(getdata(t), axis, dtype=dtype or t.dtype)<EOL>mr = umath.logical_and.reduce(m, axis)<EOL>tr = tr.view(tclass)<EOL>if mr.ndim > <NUM_LIT:0>:<EOL><INDENT>tr._mask = mr<EOL>return tr<EOL><DEDENT>elif mr:<EOL><INDENT>return masked<EOL><DEDENT>return tr<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 = umath.logical_or.outer(ma, mb)<EOL><DEDENT>if (not m.ndim) and m:<EOL><INDENT>return masked<EOL><DEDENT>(da, db) = (getdata(a), getdata(b))<EOL>d = self.f.outer(da, db)<EOL>if d is NotImplemented:<EOL><INDENT>return NotImplemented<EOL><DEDENT>if m is not nomask:<EOL><INDENT>np.copyto(d, da, where=m)<EOL><DEDENT>if d.shape:<EOL><INDENT>d = d.view(get_masked_subclass(a, b))<EOL>d._mask = m<EOL><DEDENT>return d<EOL>

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


def accumulate (self, target, axis=<NUM_LIT:0>):

if isinstance(target, MaskedArray):<EOL><INDENT>tclass = type(target)<EOL><DEDENT>else:<EOL><INDENT>tclass = MaskedArray<EOL><DEDENT>t = filled(target, self.filly)<EOL>return self.f.accumulate(t, axis).view(tclass)<EOL>

Accumulate `target` along `axis` after filling with y fill
        value.


def __init__ (self, dbfunc, domain, fillx=<NUM_LIT:0>, filly=<NUM_LIT:0>):

self.f = dbfunc<EOL>self.domain = domain<EOL>self.fillx = fillx<EOL>self.filly = filly<EOL>self.__doc__ = getattr(dbfunc, "<STR_LIT>", str(dbfunc))<EOL>self.__name__ = getattr(dbfunc, "<STR_LIT>", str(dbfunc))<EOL>ufunc_domain[dbfunc] = domain<EOL>ufunc_fills[dbfunc] = (fillx, filly)<EOL>


def __call__(self, a, b, *args, **kwargs):

<EOL>(da, db) = (getdata(a, subok=False), getdata(b, subok=False))<EOL>(ma, mb) = (getmask(a), getmask(b))<EOL>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>result = self.f(da, db, *args, **kwargs)<EOL><DEDENT>if result is NotImplemented:<EOL><INDENT>return NotImplemented<EOL><DEDENT>m = ~umath.isfinite(result)<EOL>m |= ma<EOL>m |= mb<EOL>domain = ufunc_domain.get(self.f, None)<EOL>if domain is not None:<EOL><INDENT>m |= filled(domain(da, db), True)<EOL><DEDENT>if (not m.ndim):<EOL><INDENT>if m:<EOL><INDENT>return masked<EOL><DEDENT>else:<EOL><INDENT>return result<EOL><DEDENT><DEDENT>np.copyto(result, da, casting='<STR_LIT>', where=m)<EOL>result = result.view(get_masked_subclass(a, b))<EOL>result._mask = m<EOL>if isinstance(b, MaskedArray):<EOL><INDENT>if isinstance(a, MaskedArray):<EOL><INDENT>result._update_from(a)<EOL><DEDENT>else:<EOL><INDENT>result._update_from(b)<EOL><DEDENT><DEDENT>elif isinstance(a, MaskedArray):<EOL><INDENT>result._update_from(a)<EOL><DEDENT>return result<EOL>


self._display = display<EOL>self._enabled = True<EOL>


return self._display<EOL>

Display the string to print for masked values.


self._display = s<EOL>

Set the string to print for masked values.


return self._enabled<EOL>

Is the use of the display value enabled?


self._enabled = shrink<EOL>


methdoc = getattr(ndarray, self.__name__, None) orgetattr(np, self.__name__, None)<EOL>if methdoc is not None:<EOL><INDENT>return methdoc.__doc__<EOL><DEDENT>

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


d = next(self.dataiter)<EOL>if self.maskiter is not None:<EOL><INDENT>m = next(self.maskiter)<EOL>if isinstance(m, np.void):<EOL><INDENT>return mvoid(d, mask=m, hardmask=self.ma._hardmask)<EOL><DEDENT>elif m:  <EOL><INDENT>return masked<EOL><DEDENT><DEDENT>return d<EOL>

Return the next value, or raise StopIteration.

Examples
--------
>>> x = np.ma.array([3, 2], mask=[0, 1])
>>> fl = x.flat
>>> fl.next()
3
>>> fl.next()
masked_array(data = --,
             mask = True,
       fill_value = 1e+20)
>>> fl.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ralf/python/numpy/numpy/ma/core.py", line 2243, in next
    d = self.dataiter.next()
StopIteration