numpy.ma.set_fill_value — NumPy v2.6.dev0 Manual

ma.set_fill_value(a, fill_value)

[source]

#

Set the filling value of a, if a is a masked array.

This function changes the fill value of the masked array a in place. If a is not a masked array, the function returns silently, without doing anything.

Parameters:aarray_likeInput array.

fill_valuedtypeFilling value. A consistency test is performed to make sure the value is compatible with the dtype of a.

Returns:NoneNothing returned by this function.

Examples

>>> importnumpyasnp>>> importnumpy.maasma>>> a=np.arange(5)>>> aarray([0, 1, 2, 3, 4])>>> a=ma.masked_where(a<3,a)>>> amasked_array(data=[--, --, --, 3, 4], mask=[ True, True, True, False, False], fill_value=999999)>>> ma.set_fill_value(a,-999)>>> amasked_array(data=[--, --, --, 3, 4], mask=[ True, True, True, False, False], fill_value=-999)Nothing happens if a is not a masked array.

>>> a=list(range(5))>>> a[0, 1, 2, 3, 4]>>> ma.set_fill_value(a,100)>>> a[0, 1, 2, 3, 4]>>> a=np.arange(5)>>> aarray([0, 1, 2, 3, 4])>>> ma.set_fill_value(a,100)>>> aarray([0, 1, 2, 3, 4])