Bincount

import numpy as np
a = np.array([1, 2, 4, 5])
b = np.bincount(a)
b
array([0, 1, 1, 0, 1, 1])
b.size
6