Related Articles
How to get the unique elements of an array using NumPy?
• Last Updated : 02 Sep, 2020

Let’s see How to get the unique elements of an array using NumPy. So for finding unique elements from the array we are using numpy.unique() function of NumPy library.

Syntax: np.unique(Array)
Return: Return the unique of an array.

Now, Let’s see the examples:

Example 1:

## Python3

 `# import library``import` `numpy as np             `` ` `# create 1d-array``arr ``=` `np.array([``3``, ``3``, ``4``, ``                ``5``, ``6``, ``5``,``                ``6``, ``4``])`` ` `# find unique element ``# from a array``rslt ``=` `np.unique(arr)`` ` `print``(rslt)`

Output:

`[3 4 5 6]`

Example 2:

## Python3

 `# imoprt library``import` `numpy as np`` ` `# create a numpy 2d-array``arr ``=` `np.array([[``9``, ``9``, ``7``, ``7``],``              ``[``3``, ``4``, ``3``, ``4``]])`` ` `# find unique element``# from a array``rslt ``=` `np.unique(arr)`` ` `print``(rslt)`

Output:

`[3 4 7 9]`

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up