Last active
July 16, 2023 16:54
-
-
Save sidisinsane/44e5c37a2d41d19e185b9cbfbef68890 to your computer and use it in GitHub Desktop.
Return a list containing unique values from a given array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def list_unique(arr): | |
""" | |
Return a list containing unique values from a given array. | |
Args: | |
arr (list or numpy.ndarray): The input list. | |
Returns: | |
list: A list containing unique values. | |
Example: | |
>>> arr = [1, 2, 3, 2, 4, 1, 5] | |
>>> lst_unique = list_unique(arr) | |
>>> lst_json = json.dumps(lst_unique, indent=2, ensure_ascii=False) | |
>>> print(lst_json) | |
[ | |
1, | |
2, | |
3, | |
4, | |
5 | |
] | |
""" | |
return np.unique(np.array(arr)).tolist() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment