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

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

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

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

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

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

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