numpy.ma.masked_object#

ma.masked_object(x,value,copy=True,shrink=True)[source]#

Mask the arrayx where the data are exactly equal to value.

This function is similar tomasked_values, but only suitablefor object arrays: for floating point, usemasked_values instead.

Parameters:
xarray_like

Array to mask

valueobject

Comparison value

copy{True, False}, optional

Whether to return a copy ofx.

shrink{True, False}, optional

Whether to collapse a mask full of False to nomask

Returns:
resultMaskedArray

The result of maskingx where equal tovalue.

See also

masked_where

Mask where a condition is met.

masked_equal

Mask where equal to a given value (integers).

masked_values

Mask using floating point equality.

Examples

>>>importnumpyasnp>>>importnumpy.maasma>>>food=np.array(['green_eggs','ham'],dtype=object)>>># don't eat spoiled food>>>eat=ma.masked_object(food,'green_eggs')>>>eatmasked_array(data=[--, 'ham'],             mask=[ True, False],       fill_value='green_eggs',            dtype=object)>>># plain ol` ham is boring>>>fresh_food=np.array(['cheese','ham','pineapple'],dtype=object)>>>eat=ma.masked_object(fresh_food,'green_eggs')>>>eatmasked_array(data=['cheese', 'ham', 'pineapple'],             mask=False,       fill_value='green_eggs',            dtype=object)

Note thatmask is set tonomask if possible.

>>>eatmasked_array(data=['cheese', 'ham', 'pineapple'],             mask=False,       fill_value='green_eggs',            dtype=object)
On this page