Last active
July 16, 2023 16:55
-
-
Save sidisinsane/be49603a3317b9a1b8c631a24f38017e to your computer and use it in GitHub Desktop.
Return an array 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 array_unique(arr): | |
""" | |
Return an array containing unique values from a given array. | |
Args: | |
arr (list or numpy.ndarray): The input array. | |
Returns: | |
numpy.ndarray: An array containing unique values. | |
Example: | |
>>> arr = [1, 2, 3, 2, 4, 1, 5] | |
>>> arr_unique = array_unique(arr) | |
>>> print(arr_unique) | |
[1, 2, 3, 4, 5] | |
""" | |
return np.unique(np.array(arr)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment