summaryrefslogtreecommitdiff
path: root/numpy/ma/extras.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r--numpy/ma/extras.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index d2986012b..4e7f8e85e 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1104,6 +1104,32 @@ def unique(ar1, return_index=False, return_inverse=False):
--------
numpy.unique : Equivalent function for ndarrays.
+ Examples
+ --------
+ >>> import numpy.ma as ma
+ >>> 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,