diff options
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 22687b941..6cca1738b 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -206,6 +206,7 @@ def unique(ar, return_index=False, return_inverse=False, -------- numpy.lib.arraysetops : Module with a number of other functions for performing set operations on arrays. + repeat : Repeat elements of an array. Notes ----- @@ -244,7 +245,7 @@ def unique(ar, return_index=False, return_inverse=False, >>> a[indices] array(['a', 'b', 'c'], dtype='<U1') - Reconstruct the input array from the unique values: + Reconstruct the input array from the unique values and inverse: >>> a = np.array([1, 2, 6, 4, 2, 3, 2]) >>> u, indices = np.unique(a, return_inverse=True) @@ -255,6 +256,17 @@ def unique(ar, return_index=False, return_inverse=False, >>> u[indices] array([1, 2, 6, 4, 2, 3, 2]) + Reconstruct the input values from the unique values and counts: + + >>> a = np.array([1, 2, 6, 4, 2, 3, 2]) + >>> values, counts = np.unique(a, return_counts=True) + >>> values + array([1, 2, 3, 4, 6]) + >>> counts + array([1, 3, 1, 1, 1]) + >>> np.repeat(values, counts) + array([1, 2, 2, 2, 3, 4, 6]) # original order not preserved + """ ar = np.asanyarray(ar) if axis is None: |