Skip to content

Commit

Permalink
DOC: add example for ma.unique function
Browse files Browse the repository at this point in the history
  • Loading branch information
swagatip committed Sep 16, 2022
1 parent 5f94eb8 commit 1d556d9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions numpy/ma/extras.py
Expand Up @@ -1104,6 +1104,31 @@ def unique(ar1, return_index=False, return_inverse=False):
--------
numpy.unique : Equivalent function for ndarrays.
Examples
--------
>>> a = [1, 2, 1000, 2, 3]
>>> mask = [0, 0, 1, 0, 0]
>>> masked_a = ma.masked_array(a, mask)
>>> masked_a
masked_array(data=[1, 2, --, 2, 3],
mask=[False, False, True, False, False],
fill_value=999999)
>>> ma.unique(masked_a)
masked_array(data=[1, 2, 3, --],
mask=[False, False, False, True],
fill_value=999999)
>>> 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]))
>>> 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]))
>>> 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]))
"""
output = np.unique(ar1,
return_index=return_index,
Expand Down

0 comments on commit 1d556d9

Please sign in to comment.