NumPy

Previous topic

numpy.ma.MaskedArray.nonzero

Next topic

numpy.ma.MaskedArray.repeat

This is documentation for an old release of NumPy (version 1.18). Read this page in the documentation of the latest stable release (version 2.2).

numpy.ma.MaskedArray.put

method

MaskedArray.put(self, indices, values, mode='raise')[source]

Set storage-indexed locations to corresponding values.

Sets self._data.flat[n] = values[n] for each n in indices. If values is shorter than indices then it will repeat. If values has some masked values, the initial mask is updated in consequence, else the corresponding values are unmasked.

Parameters
indices1-D array_like

Target indices, interpreted as integers.

valuesarray_like

Values to place in self._data copy at target indices.

mode{‘raise’, ‘wrap’, ‘clip’}, optional

Specifies how out-of-bounds indices will behave. ‘raise’ : raise an error. ‘wrap’ : wrap around. ‘clip’ : clip to the range.

Notes

values can be a scalar or length 1 array.

Examples

>>>
>>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.put([0,4,8],[10,20,30])
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 20, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>>
>>> x.put(4,999)
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 999, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)