On this page
numpy.ma.where
numpy.ma.where(condition, x=<class numpy._globals._NoValue at 0x40b6a26c>, y=<class numpy._globals._NoValue at 0x40b6a26c>)
[source]-
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
whencondition
is True, and fromy
otherwise. If neitherx
nory
are given, the function returns a tuple of indices wherecondition
is True (the result ofcondition.nonzero()
).Parameters: condition : array_like, bool
The condition to meet. For each True element, yield the corresponding element from
x
, otherwise fromy
.x, y : array_like, optional
Values from which to choose.
x
andy
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
andy
were given, otherwise the result ofcondition.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]]
© 2008–2017 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.ma.where.html