How to remove duplicates from NumPy array

You can remove duplicates from the NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

Remove duplicates from the NumPy array

# Import the NumPy Library
import numpy as np

# Initialize the Array
a = np.array([1, 1, 2, 3, 4, 10, 1])

# Display 
print(np.unique(a))

Output:

[ 1  2  3  4 10]

Free Learning Resources

Leave a Comment

Your email address will not be published.