numpy.ma.putmask#

ma.putmask(a, mask, values)[source]#

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.

Examples

>>> arr = [[1, 2], [3, 4]]
>>> mask = [[1, 0], [0, 0]]
>>> x = np.ma.array(arr, mask=mask)
>>> np.ma.putmask(x, x < 4, 10*x)
>>> x
masked_array(
  data=[[--, 20],
        [30, 4]],
  mask=[[ True, False],
        [False, False]],
  fill_value=999999)
>>> x.data
array([[10, 20],
       [30,  4]])