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

ma.unique(ar1, return_index=False, return_inverse=False)

[source]

#

Finds the unique elements of an array.

Masked values are considered the same element (masked). The output array is always a masked array. See

numpy.unique

for more details.

Examples

>>> importnumpyasnp>>> a=[1,2,1000,2,3]>>> mask=[0,0,1,0,0]>>> masked_a=np.ma.masked_array(a,mask)>>> masked_amasked_array(data=[1, 2, --, 2, 3], mask=[False, False, True, False, False], fill_value=999999)>>> np.ma.unique(masked_a)masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999)>>> np.ma.unique(masked_a,return_index=True)(masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 4, 2]))>>> np.ma.unique(masked_a,return_inverse=True)(masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 3, 1, 2]))>>> np.ma.unique(masked_a,return_index=True,return_inverse=True)(masked_array(data=[1, 2, 3, --], mask=[False, False, False, True], fill_value=999999), array([0, 1, 4, 2]), array([0, 1, 3, 1, 2]))