Python | Numpy np.unique () method

NumPy | Python Methods and Functions

Using the np.unique() method, we can get unique values ​​from the array given as a parameter in np.unique () .

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

Example # 1:
In this example we can see that with np.unique () we can get unique values ​​from the array using this method.

# NumPy imports

import numpy as np

  

a = [ 1 , 2 , 2 , 4 , 3 , 6 , 4 , 8 ]

 
# using the np.unique () method

gfg = np.unique (a)

 

print (gfg)

Output:

[1 2 3 4 6 8]

Example # 2:

# NumPy import

import numpy as np

 

a = [[ 10.2 , 21.4 , 3.6 , 14.8 ], [ 1.0 , 5.0 , 10.0 , 15.0 ]]

 
# using the np.unique () method

gfg = np.unique (a)

 

print < / code> (gfg)

Output:

[1. 3.6 5. 10. 10.2 14.8 15. 21.4]





Get Solution for free from DataCamp guru