Skip to content

Instantly share code, notes, and snippets.

@sidisinsane
Last active July 16, 2023 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidisinsane/be49603a3317b9a1b8c631a24f38017e to your computer and use it in GitHub Desktop.
Save sidisinsane/be49603a3317b9a1b8c631a24f38017e to your computer and use it in GitHub Desktop.
Return an array containing unique values from a given array.
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