9951 explained code solutions for 126 technologies

python-numpyHow to count unique values

import numpy as np
a = np.array([1,1,2,1,2])
uniq = np.unique(a).sizectrl + c
import numpy as np

load Numpy module for Python


declare Numpy array


sample array


returns unique values only from specified array


attribute contains number of elements in an array


will contain number of unique elements