Skip to content

Commit

Permalink
Merge pull request #22436 from cmarmo/doc-masked-equal
Browse files Browse the repository at this point in the history
DOC: Clarify docstring of `masked_equal` and `masked_values`
  • Loading branch information
seberg committed Nov 21, 2022
2 parents 098dbdd + 918f81d commit f92c90c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,9 +2081,11 @@ def masked_equal(x, value, copy=True):
"""
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)``.
Return a MaskedArray, masked where the data in array `x` are
equal to `value`. The fill_value of the returned MaskedArray
is set to `value`.
For floating point arrays, consider using ``masked_values(x, value)``.
See Also
--------
Expand Down Expand Up @@ -2303,25 +2305,17 @@ def masked_values(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True):
Note that `mask` is set to ``nomask`` if possible.
>>> ma.masked_values(x, 1.5)
>>> ma.masked_values(x, 2.1)
masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
mask=False,
fill_value=1.5)
fill_value=2.1)
For integers, the fill value will be different in general to the
result of ``masked_equal``.
Unlike `masked_equal`, `masked_values` can perform approximate equalities.
>>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> ma.masked_values(x, 2)
masked_array(data=[0, 1, --, 3, 4],
>>> ma.masked_values(x, 2.1, atol=1e-1)
masked_array(data=[1.0, 1.1, --, 1.1, 3.0],
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=2)
fill_value=2.1)
"""
xnew = filled(x, value)
Expand Down

0 comments on commit f92c90c

Please sign in to comment.