How to count unique values in NumPy array

You can count unique values in the NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.

How to count unique values in NumPy array
How to count unique values in NumPy array
import numpy as np
a = np.array([5, 10, 5, 5, 15, 10, 5])
(unique, counts) = np.unique(a, return_counts=True)
print(unique, counts)

Output

[ 5 10 15] [4 2 1]

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.