Update README.md

Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
David Rotermund 2023-12-29 19:10:19 +01:00 committed by GitHub
parent e7f6e2d747
commit 3002868586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,3 +25,37 @@ numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False,
> * the indices of the unique array that reconstruct the input array > * the indices of the unique array that reconstruct the input array
> * the number of times each unique value comes up in the input array > * the number of times each unique value comes up in the input array
**unique can be used on multi-dimensional arrays. However, the results are strange since empty places need to be filled for shaping the results into one common matrix.**
```python
import numpy as np
a = np.arange(10, 21)
print(a) # -> [10 11 12 13 14 15 16 17 18 19 20]
idx = np.r_[0:5, 3:8]
print(idx) # -> [0 1 2 3 4 3 4 5 6 7]
print(a[idx]) # -> [10 11 12 13 14 13 14 15 16 17]
print(np.unique(idx)) # -> [0 1 2 3 4 5 6 7]
print(np.unique(a[idx])) # -> [10 11 12 13 14 15 16 17]
```
## There are more return arguments available
```python
import numpy as np
a = np.r_[0:5, 3:8]
print(a) # -> [0 1 2 3 4 3 4 5 6 7]
values, unique_index = np.unique(a, return_index=True)
_, unique_inverse = np.unique(a, return_inverse=True)
_, unique_counts = np.unique(a, return_counts=True)
print(values) # -> [0 1 2 3 4 5 6 7]
print(unique_index) # -> [0 1 2 3 4 7 8 9]
print(unique_inverse) # -> [0 1 2 3 4 3 4 5 6 7]
print(unique_counts) # -> [1 1 1 2 2 1 1 1]
```