def where (condition, x=None, y=None):
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]]